Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Sorting data after 'addRowData'
Tags: sort
29/10/2010
11:29
Avatar
liny
Member
Members
Forum Posts: 5
Member Since:
29/10/2010
sp_UserOfflineSmall Offline

Hi,

Below is my javascript:

                            myGrid=$("#myXXTable").jqGrid({
                                datatype: "local",
                                rowNum:16,
                                colNames:['FACILITY','DEVICE', 'LOT', 'QTY','CUM AGE'],
                                colModel:[ {name:'facility',index:'facility', width:100, sortable:false, hidden: true},
                                    {name:'device',index:'device', width:100, sortable:false, hidden: true},
                                    {name:'lot',index:'lot', width:100, align:"center", sorttype:"string"},
                                    {name:'qty',index:'qty', width:100, align:"right",sorttype:"int"},
                                    {name:'cumAge',index:'cumAge', width:100, align:"right",sorttype:"float"}
                                ],
                                sortname:'cumAge',
                                sortorder:'asc',
                                multiselect: false,
                                caption: "Lot Cum Age Report - " + device
                            });

                            $('#myXXTable').jqGrid('clearGridData');

                            for(var i=0;i<=cumAgeArray.length;i++)
                            {
                                $("#myXXTable").jqGrid('addRowData',i+1,cumAgeArray[i]);
                            }

After 'addRowData', jqGrid doesn't sort by cumAge asc,

Can someone tell me how to enforce jqGrid to sort data?

Thank you very much.

29/10/2010
12:58
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

The grid does not know which data act as ID.

Please set key:true for a field that should  do this and you will happy or configure the localReader 

/jqgridwiki/doku.php?id=wiki:retrieving_data&s[]=localreader#array_data

regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

29/10/2010
18:05
Avatar
liny
Member
Members
Forum Posts: 5
Member Since:
29/10/2010
sp_UserOfflineSmall Offline

Hi, Tony,

I modified the javascript:

                            myGrid=$("#myXXTable").jqGrid({
                                datatype: "local",
                                rowNum:16,
                                colNames:['FACILITY','DEVICE', 'LOT', 'QTY','CUM AGE'],
                                colModel:[ {name:'facility',index:'facility', width:100, sortable:false, hidden: true},
                                    {name:'device',index:'device', width:100, sortable:false, hidden: true},
                                    {name:'lot',index:'lot', width:100, align:"center", sorttype:"string", key:true},
                                    {name:'qty',index:'qty', width:100, align:"right",sorttype:"int"},
                                    {name:'cumAge',index:'cumAge', width:100, align:"right",sorttype:"float", firstsortorder:"asc"}
                                ],
                                sortname:'cumAge',
                                sortorder:'asc',
                                multiselect: false,
                                caption: "Lot Cum Age Report – " + device
                            });

                            $('#myXXTable').jqGrid('clearGridData');

                            for(var i=0;i<=cumAgeArray.length;i++)
                            {
                                $("#myXXTable").jqGrid('addRowData',i+1,cumAgeArray[i]);
                            }

It still doesn't work.

I just want to automative sort "cumAge" column asc after "addRowData", not user click the column to sort on the web page.

Any hint is welcome. Thanks in advance.

30/10/2010
01:20
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

If you don't want to add information about ids to the data which you add you can force sorting with a simple reloading of grid:

$("#myXXTable").trigger("reloadGrid");

or

$("#myXXTable").setGridParam({rowNum:16}).trigger("reloadGrid");

I hope that it will work.

Best regards

Oleg

01/11/2010
11:42
Avatar
liny
Member
Members
Forum Posts: 5
Member Since:
29/10/2010
sp_UserOfflineSmall Offline

OlegK said:

If you don't want to add information about ids to the data which you add you can force sorting with a simple reloading of grid:

$("#myXXTable").trigger("reloadGrid");

or

$("#myXXTable").setGridParam({rowNum:16}).trigger("reloadGrid");

I hope that it will work.

Best regards

Oleg


Hi,

I don't quite understand what the "add information about ids" is, could you kindly explain more detail? Thank you very much.

01/11/2010
13:38
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

If every element of your data from cumAgeArray would be have an additional property id you can use data parameter of jqGrid to place the data at the initialization time in the grid. Hot I can see now you use key:true for the lot column. If your evry data row has really unique data in this column, then you don't need use additional property id and just add data: cumAgeArray as additional parameter of jqGrid (I suppose that elements of cumAgeArray has the same properties as the name properties from the colModel).

Best regards
Oleg 

01/11/2010
14:16
Avatar
liny
Member
Members
Forum Posts: 5
Member Since:
29/10/2010
sp_UserOfflineSmall Offline

Hi, thanks for your guys.

Finally! Last line code below is the answer.

                            $("#myXXTable").jqGrid({
                                data:cumAgeArray,
                                datatype: "local",
                                rowNum:10,
                                autowidth: true,
                                height:'500',
                                hidegrid:false,
                                deselectAfterSort:false,
                                colNames:['FACILITY','DEVICE', 'LOT', 'QTY','CUM AGE', 'RESIDUAL', 'OTD_TYPE'],
                                colModel:[ {name:'facility',index:'facility', sortable:false, hidden: true},
                                    {name:'device',index:'device', sortable:false, hidden: true},
                                    {name:'lot',index:'id', align:"center", sorttype:"text", key:true},
                                    {name:'qty',index:'qty', align:"right",sorttype:"int"},
                                    {name:'cumAge',index:'cumAge', align:"right",sorttype:"float"},
                                    {name:'residual',index:'residual', align:"center",sorttype:"text"},
                                    {name:'otdType',index:'otdType', align:"center",sorttype:"text"}
                                ],
                                multiselect: false,
                                pager:'#pager',
                                sortname:'cumAge',
                                sortorder:$('input:radio[name=sortBy]:checked').val(),
                                caption: "Lot Cum Age Report - " + device
                            });
                           
                            $("#myXXTable").setGridParam({data:cumAgeArray, rowNum:cumAgeArray.length, sortorder:$('input:radio[name=sortBy]:checked').val()}).trigger("reloadGrid");
01/11/2010
14:42
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Sorry liny, but you write no time about any radio button sortBy. If you use some external elements for jqGrid sorting and place the data not one during creating the grid as you write it is absolutely another situation.

If you want reload the grid with new data you should probably place setGridParam inside of 'change' or 'click' event handler. Moreover refreshing of jqGrid indexes with $("#myXXTable")[0].refreshIndex(); could be also required after this data settings.

Regards
Oleg 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
66 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information