JqGrid: mess when cellattr returns a string containing "style"

Background:

I came across a strange behavior in jqGrid: when the callback cellattrreturns a string containing the "style", the grid becomes messy.

See an example:

HTML:

<table id="grid"></table>

Javascript

$("#grid").jqGrid({
    datatype: "local",
    height: "auto",
    data: [{column1: "row1col1", column2: "row1col2" },
        {column1: "row2col2", column2: "row2col2" }],
    colNames: ['Column1', 'Column2'],
    colModel: [
    {
        name: 'column1',
        index: 'column1',
        cellattr: function (rowId, val, rawObject, cm, rdata) {
            attrValue = (rawObject.column2 == 'row2col2') ? 'GangnamStyleAttribute' : 'GangnamAttribute';
            return ' customAttr="' + attrValue + '"';
        },
        width: 100
    },
    {
        name: 'column2',
        index: 'column2',
        width: 100
    }],
    caption: "Qaru Example",
});

$("#grid").jqGrid('setGridParam');

Also see jsfiddle

In the above example, it cellattrreturns' customAttr = "GangnamAttribute" 'for the first line and' customAttr = "GangnamStyleAttribute" for the second line.

As you can see from jsfiddle , the first row is displayed correctly, and the second is confused: the first column is not shown, and the second column is displayed instead of the first.

, cellattr -, " ".

: - , , " "?

+4
2

, .

- , jqGrid , cellatr. , . jqGrid "".

, :

return ' style="" customAttr: "' + attrValue + '"'

. jsfiddle

+2

, , , , ​​ jqGrid 4.7.0, jqGrid .

0

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


All Articles