How to implement custom sorting for a specific column after jqgrid is created?

Is there a way I can use to overwrite / insert a custom "sorttype" function for a specific column in colModel after it has been populated with javascript (jQuery)?

I found an example here: http://www.ok-soft-gmbh.com/jqGrid/CustomSorttype1.htm , where sorttype is implemented with the initial settings, but what do I need to change after.

I tried:

var attName = grid.getGridParam("colModel")[1].name;
        grid.setColProp(attName, { sorttype: function (cell) {
            if (cell == '<div>x</div>') { return '0' } else { return '1' };
        }
        });

but does not work.

+2
source share
1 answer

sorttype jqGrid loadonce:true jqGrid paremter "remote" json '' xml. , sorttype .

, . "", .

enter image description here

Wenn " sorttype", ,

enter image description here

​​,

var myCustomSort = function(cell,rowObject) {
    if (typeof cell === "string" && /^test(\d)+$/i.test(cell)) {
        return parseInt(cell.substring(4),10);
    } else {
        return cell;
    }
}

"change"

$("#customsorttype").change(function() {
    var isChecked = $(this).is(':checked');
    if (isChecked) {
        cm.sorttype = myCustomSort;
    } else {
        cm.sorttype = "text";
    }
    grid.trigger("reloadGrid");
});

grid - $("#list").

, sorttype:"text".

+9

All Articles