Question

I have a column "Amount" on the jqGrid. When I click on top of "Amount" column, the grid needs to be sorted by another column called "Amount Payable".

How can I achieve this.

Thanks, Sam

Was it helpful?

Solution 2

If you define the onSortCol function you could test for the column being sorted and then change the value.

Ex.

onSortCol: function (index, iCol, sortorder) {    
    if(index === "Amount"){
        index = "AmountPayable";              
    }
},

OTHER TIPS

You don't posted the code of jqGrid which you use. What you should try to do as the first is the set index property for Amount column in the value of name of column which you called as "Amount Payable"`.

Another way would be to use sorttype property for Amount column defined as function. The way works in case of usage datatype: "local" or in case of usage loadonce: true option with remote datatype ("json", "jsonp" or "xml"). What you need to do is just add sorttype property for Amount column defined about as following:

{
    name: "Amount",
    sorttype: function (cellValue, rowData) {
        return rowData.AmountPayable; // use the value from another column for
                                      // defining of the position of sorted rows
    }}

See the answer or this one for another code examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top