Forum



11:29

29/10/2010

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.
12:58

Moderators
30/10/2007

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.
18:05

29/10/2010

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.
11:42

29/10/2010

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.
13:38

10/08/2009

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
14:16

29/10/2010

Hi, thanks for your guys.
Finally! Last line code below is the answer.
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");
14:42

10/08/2009

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
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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66