jQWidgets Forums
jQuery UI Widgets › Forums › General Discussions › Plugins › Data Adapter › Passing json string to dataadapter from server
Tagged: dataadapter
This topic contains 4 replies, has 2 voices, and was last updated by jbachus 11 years ago.
-
Author
-
I have an application that passes a source to a dataadapter and returns a formatted json string from a webservice.
the json string is returned correctly along with the source changed since it could be many different tables.Here is a snippet
initialize the source data for the grid to be empty. change source and url when user selects recordsource = { contentType: "application/json; charset=utf-8", datatype: 'json', datafields: [ { name: 'ID', type: 'int' } ], id: 'ID', url: '' }; dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function (data) { var length = dataAdapter.records.length; }, loadError: function (jqXHR, status, error) { var test = status; }, downloadComplete: function (data, status, xhr) { ReturnData = data; } }); if (dataAdapter == null) { dataAdapter = new $.jqx.dataAdapter(source, { autobind: true }); } $("#jqxgrid").jqxGrid( { width: '100%', height: '100%', theme: 'ui-redmond', source: dataAdapter, sortable: true, filterable: true, columnsresize: true, localization: getLocalization(), selectionmode: 'checkbox', autoshowloadelement: true, ready: function () { }, // called when the Grid is loaded. Call methods or set properties here. altrows: true });
The DataAdapter returns the appropriate JSON string but in the load complete it retruns the data as a JSON String but the record length is one as if it is not getting anything but 1 long string. I change the Datafields and columns Based on the Data that is retrieved. It goes to the server gets the data and comes back and does not bind to grid. The Data fields, and columns are changed dynamically. and the url returns the correct data. What am I doing incorrectly?
Hi jbachus,
The columns property is not set. That’s something which is missing in your code. It should be set during the Grid’s initialization process.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comI dynamically set the Source properties value with different fields based on the users selection so just before the UpdateBounddata call I set the grids columns. also I get the data back and when it comes there is an object expected and I get an error in some procedure called sizzle, I noticed the same thing happening to someone else in this forum. if I call a separate ajax call and pass assign the same return value to localdata it works fine, but I get no loading icon from the grid since I am loading it thru localdata and it locks the system while loading. calling the show and hide of the icon does not function either. Trying to open a jqxWindow, using blockUI, I have tried them all…the only thing that gets called is an alert…I have also tried the dataset writexml to no avail either. I am using 3.4 the latest version of jquery (1.11) and unfortunately working with IE8…As this is the first experience with JQXWidgets I think they are great. I am still learning the INS and outs but it has been a pleasure using them I would hate to go back and write everything on the server.
Hi jbachus,
Can’t you make one request for your Data and Columns? In the dataAdapter’s beforeLoadComplete, parse the columns which you received from your server.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comI have it working although I thought that I had tried this before but this call made it work.
dataAdapter = new $.jqx.dataAdapter(source, { downloadComplete: function (data, status, xhr) { return jQuery.parseJSON(data.d); } });
Thanks for the assistance…
-
AuthorPosts
You must be logged in to reply to this topic.