jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Can't enable default sort on Grid
Tagged: grid sort sortcolumn
This topic contains 10 replies, has 2 voices, and was last updated by Peter Stoev 9 years, 6 months ago.
-
Author
-
I have a grid who is loaded via JSON. I want the grid to have an initial set of GROUPINGS and SORT. While I can get the initial grouping setup, via the grid constructor, I cannot get the initial SORT to work properly. Here is my source definition. If I comment out sortcolumn, everything is fine. If I enable the sortcolumn parameter, I get the error
Uncaught... :cannot read property 'children' of undefined var source = { localdata: data3, datatype: "json", root: 'rows', sortcolumn: 'TECH_MAPPING' };
Here is my column definition (in the grid constructor.
{ text: 'Tech Mapping ', datafield: 'TECH_MAPPING', width: 100 },
What am I doing wrong?
Also, is it possible to set two sort columns, if so, how?Hi George,
1. It is shown on this demo how to do it: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/sorting.htm?arctic
2. No.Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Yes, I see the demo. In the source definition, I have added the sortcolumn setting. (I have also tried adding ‘sortdirection’). My datasource is JSON. As such, it does not need to have each column defined. The grid is showing all my columns, without me having to define them all in the dataAdapter.source definition. If I put in sortcolumn, then I get the error ‘Uncaught… :cannot read property ‘children’ of undefined’.
Is there any example of default sorting with JSON?
Hi George,
Binding to JSON is demonstrated in many of the Grid’s demos like: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/bindingtojson.htm?arctic, http://www.jqwidgets.com/jquery-widgets-demo/demos/php/grid.htm?arctic, etc. Defining the data fields in the adapter’s source object and setting the field’s type is mandatory.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/I must be missing something. My entire source definition is blow. This is showing 30+ fields, and I have NOT defined the field data type. Everything appears to be working fine, EXCEPT having an initial sort.
var source = { localdata: data3, datatype: "json", root: 'rows' }; var dataAdapter = new $.jqx.dataAdapter(source); // Create jqxGrid $("#productListDetail").jqxGrid({ width: '100%', source: dataAdapter, ...
My BINDING to JSON is working fine. My question is… do you have an example of JSON with a default sort?
Hi George S,
Yes, are missing very important parts of the binding process. datafields in the source object are undefined. sortcolumn and sortdirection are undefined, too. What kind of sorting want to be applied when these are undefined? I suggest you to look at: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/sorting.htm?arctic and especially the code. Then follow the same approach.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Additional info… I did go ahead and add all the field definitions in the dataAdapter definition. (both name: and type: attributes). That does not help my issue. I still get ‘Uncaught… :cannot read property ‘children’ of undefined’. I get no errors without the sortcolumn attribute.
DataAdapter definition is now…
var source = { localdata: data3, datatype: "json", root: 'rows', datafields: [ { name: 'NN_NAME', type: 'string' }, { name: 'DUNS_NUMBER', type: 'string' }, { name: 'FY', type: 'string' }, { name: 'FY_QTR', type: 'string' }, { name: 'OVI_INDUSTRY_BY_NN', type: 'string' }, { name: 'TECH_MAPPING', type: 'string' }, ... ], sortcolumn: 'TECH_MAPPING', };
If I comment out ‘sortcolumn’, everything works fine. Any idea what I am doing wrong?
Thanks
typo…. that last COMMA (after TECH_MAPPING) should not be there. It is NOT in my source code
Hi George S,
Where’s the sortdirection?
Where are the columns defined?
Provide a jsfiddle.net sample which demonstrates your issue so someone can test your code.Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/How do I provide a jsfiddle with JSON?
-
AuthorPosts
You must be logged in to reply to this topic.