JqGrid formatting and sortable column - don't sort

I use my own formatter for my jqGrid columnModel and I cannot sort to work with formatting functions. If I delete formatting columns, sortings are usually.

jQuery("#listAgentOptions").jqGrid({
    height: 240,
    datatype: "local",
    colNames: [' ', 'First Name', 'Last Name', 'Role'],
    colModel: [
    { name: 'status', index: 'status', width: 18, sorttype: 'text', align: 'center', formatter: function(cellvalue, options, rowObject) {
        return cellvalue == 1 ? "<img src='images/agent_green_s.png' alt='Ready' title='Ready' />" :
        cellvalue == 3 ? "<img src='images/agent_red_s.png' alt='Busy' title='Busy' />" :
        "<img src='images/agent_orange_s.png' alt='Pending Ready' title='Pending Ready' />";
    },
        unformat:
    function(cellvalue, options, rowObject) { return Math.floor(Math.random() + 0.1).toString(); }
    },
    { name: 'firstName', index: 'firstName', width: 92 },
    { name: 'lastName', index: 'lastName', width: 142 },
    { name: 'role', index: 'role', sorttype: 'int', width: 36, align: 'center', formatter: function(cellvalue, options, rowObject) {
        return cellvalue == true ? "<img src='images/user_gray.png' alt='Supervisor' title='Supervisor' />" : "<img src='images/user.png' alt='Agent' title='Agent' />";
    }, unformat:
    function(cellvalue, options, rowObject) { return cellvalue; }
    }
    ],
    sortname: 'lastName'
});

Lines are added as follows:

jQuery("#listAgentOptions").jqGrid('clearGridData');
$.each(result, function(i, item) {
    if (item.ContactType == 1) {
        jQuery("#listAgentOptions").jqGrid('addRowData', i+1, { firstName: item.ContactName.split(" ")[0], lastName: item.ContactName.split(" ")[1],
        role: item.IsSupervisor,
        status: item.Status == "Ready" ? 1 : item.Status == "Busy" ? 3 : 2
        });
    }
});

How to set up sorting?

Update. I just downloaded the latest jqGrid - the same issue.

I also tried using unformat: function(cellvalue, options, rowObject) { }, but the cellvalue is empty there: -E When I use it return Math.floor(Math.random() + 0.1).toString();, it sorts things randomly (every time I click), but return cellvalue;just returns an empty string.

+3
source share
4 answers

, , .

, unformat, jqGrid.

jqGrid $(row).text() unformat, html , . , , unformat, rowObject. $(rowObject).html() . .

, , , sorrtype: 'int', , return '1';.

+1

jqGrid unformat :

        $.each(ts.rows, function(index, row) {
            try { sv = $.unformat($(row).children('td').eq(col),{rowId:row.id, colModel:ts.p.colModel[col]},col,true);}
            catch (_) { sv = $(row).children('td').eq(col).text(); }
            row.sortKey = findSortKey(sv);
            rows[index] = this;
        });

sorttype, int:

            findSortKey = function($cell) {
                return IntNum($cell.replace(stripNum, ''),0);
            };

, unformat , , . , , unformat.

+2

, .

jqGrid? datatype. jqGrid , , . Formatter , . , , datatype: 'xmlstring' datatype: "clientSide", dataType:"xml" dataType:"json" dataType:"jsonp". sorttype . : url jqGrid, .

+1

Try debugging with Firebug and see what the server receives. Use sortable: true.

By the way, the parameter sorttypeonly works locally ( datatype: local).

0
source

Source: https://habr.com/ru/post/1743775/


All Articles