I have DataTable loaded dynamically, all columns are coming from Database in JSON format which aoColumns required.
I can render any column like this:
"aoColumns": [
{
"sName": "I_CPN",
"fnRender": function (oObj)
{
return a button
}
}]
Where sName is my Column name, this is static, I can get above content for aoColumns dynamically from C# code in JSON format. My problem is I am not able to put fnRender in JSON object.
How can I get fnRender so that I can render my Column as button.
JSON format can not carry function objects. Just some limited set of plain datatypes (see http://www.json.org) and everything else that can be serialized into string and deserialized back.
So you might transfer the function as string and then use eval on the JavaScript front-end to turn it back to code. See e.g. JSON.parse vs. eval() for examples of how to use eval.
Although this is possible it somehow breaks the original JSON as simple data container design.
You can also write some kind of generic fnRender function that will for instance take the column name and find corresponding button element using the getElementById() function.
Your example code is to small to provide better answer (in order to generalize we must have at least 2 examples :)
Related
I have been trying to populate my variable bar with json fields from curl's POSTFIELDS attribute when invoking my workflow from an API using PHP. Below is a simple json passed when invoking the endpoint not as part of the URL but hidden POSTed data:
{"salesValue":5000,"authorId":2}
The properties above should be injected in Formatter Node where I generate the SQL statetement used by the ODBC driver to query our back-end database. I have been told that I can only do this, for now, by using the SCRIPT Node as I do not recall C# as having support for manipulating JSON Object out of the box. If I am behind with regards to that someone please lead me to an answer.
Question is: does Flowger support JSON Serialization, Deserialization, Decoding and/or encoding? There is a framework called JSON.Net for example. Can I use this if I want to manipulate my fgRequestBody property frfom my variable bar?
Try the below steps to get the desired results:
1 - Add a variable bar with two special properties: FgRequestBody and FgRequestContentType. Make sure that you specify the content type in the workflow, which will be application/json in your instance.
2 - Add a 'JSON Convert' directly after the start node and point your variable bar FgRequestBody to the input of Json on the Json Convert. This will convert json to xml.
3 - Add a 'XFormat' node and plug the xml output from the Json Convert to the 'XML Document' property. Right click on the node and add a new custom property with the name of the field that you would like to extract. In the custom property value, add the xpath to the value. In the Expression property of the node, add your sql statement e.g.
select * from tableName where name = '{customProperty}'
The results from this will be your sql query.
Troubleshooting Tip:
Use Postman Add-In (Chrome) or RESTClient (Firefox) to verify the results. You should see the node generation in the activity log within Flowgear. If you do not see this, then add a AllowedOrigin of * in your Flowgear Site properties. See the following for reference to this:http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
I am dynamically building the colModel for my jQGrid using fields from a DataTable. Nearly all of it works as I hoped. However, I am unable to use a custom summaryType because I can't serialize without the quotes and jQgrid doesn't look for the method if in quotes.
Presently, if I don't remove the ", I get the following error when loading the grid:
Uncaught jqGrid Grouping No such method: mysum
If I remove the quotes in the table, I get the following error when serializing:
Invalid JSON primitive: mysum.
What is the best way to tackle this problem?
You will probably have to create a solution in the view using javascript. If you manually serialize the colModel to send to the view, you will have to manually deserialize. You will not be able to parse it with a JSON parser because it will not be a valid JSON string.
One possible approach would be to use eval() on the string like this:
myObject.property = eval("mysum");
It should replace the string with the function. I am not sure if it meets your needs, but will avoid both errors you listed above.
The overall objective is to get a Json representation of the query results of the SqlQuery executed. This Json will be used to create visualizations/reports on the browser using js based charting tools.
Now, controls like gridview are able to read the column names as well as the data and give us an html representation of the data. So I think it should be possible to write code such that it can read from a sql data reader and come up with a json representation.
I could not find anything in my searches which does what I want. How do I go about doing this? any pointers?
You could use an SqlDataAdapter to fill a DataSet. This blog post describes a way of converting a DataTable or DataSet into its JSON representation.
You could use the Json.Net serializer. It supports serializing a Dictionary<string,object> to a JSON object.
Another big shot would be using NHibernate and serializing the resulting objects.
Here is another link to using the Json.Net serializer for DataSets:
If you scroll down to the comments on this page you see a much shorter solution using the Dictionary approach.
This is the javascript code i tried to export my grid data in json. it throws an exception and i can't figure out why. when i downloaded the jqgrid i checked the import/export module.
I want to insert the json in a hidden field in order to get the data on the server side for validating and saving.
$('#proveObjekt2').val(JSON.stringify($("#rowed5").jqGridExport("jsonstring")));
...
<asp:HiddenField ID="proveObjekt2" runat="server" />
You use parameters of jqGridExport in the wrong form. The parameter must be an object with three possible properties: exptype, root and ident. Because default values of the parameters are
{
exptype : "xmlstring",
root: "grid",
ident: "\t"
}
the call $("#rowed5").jqGridExport("jsonstring") return XML instead of JSON. You should use
jQuery("#rowed5").jqGridExport({exptype:"jsonstring"})
or
jQuery("#rowed5").jqGrid('jqGridExport',{exptype:"jsonstring"})
instead.
We are communicating with a 3rd party service using via an XML file based on standards that this 3rd party developed. They give us an XML template for each "transaction" and we read it into a DataSet using System.Data.DataSet.ReadXML, set the proper values in the DataSet, and then write the XML back using System.Data.DataSet.WriteXML. This process has worked for several different files. However, I am now adding an additional file which requires that an integer data type be set on one of the fields. Here is a scaled down version:
<EngineDocList>
<DocVersion>1.0</DocVersion>
<EngineDoc>
<MyData>
<FieldA></FieldA>
<FieldB></FieldB>
<ClientID DataType="S32"></ClientID>
</MyData>
</EngineDoc>
</EngineDocList>
When I look at the DataSet created by my call to ReadXML to this file, the MyData table has columns of FieldA, FieldB, and MyData_ID. If I then set the value of MyData_ID and then make the call to WriteXML, the export XML has no value for ClientID. Once again, if I take a way the DataType, then I do have a ClientID column, I can set it properly, and the exported XML has the proper value. However, the third party requires that this data type be defined.
Any thoughts on why the ReadXML would be renaming this tag or how I could otherwise get this process to work? Alternatively, I could revamp the way we are reading and writing the XML, but would obviously rather not go down this path although these suggestions would also be welcome. Thanks.
I would not do this with a DataSet. It has a specific focus on simulating a relational model. Much XML will not follow that model. When the DataSet sees things that don't match it's idea of the world, it either ignores them or changes them. In neither case is it a good thing.
I'd use an XmlDocument for this.