is it possible to set alternate row backcolor on a jqgrid Treegrid

╄→尐↘猪︶ㄣ 提交于 2019-11-27 07:27:52

问题


i am starting to play around with jqGrid Treegrid but i don't see anyway to set alternative row back color. Is this possible?


回答1:


If you mean altRows and altclass parameters, then there not works. To be exactly at the tree grid initialization time (inside of setTreeGrid) some jqGrid parameters will be reset. How you can see here the value of the altRows parameter will be set to false. The reason of the change would be clear if you imagine that expanding/collapsing of tree nodes can change the order of the tree items so you would be have

from the original tree

UPDATED: A workaround is always exist. See the demo with the following code:

var resetAltRows = function () {
    // I think one can improve performance the function a little if needed,
    // but it should be done the same
    $(this).children("tbody:first").children('tr.jqgrow').removeClass('myAltRowClass');
    $(this).children("tbody:first").children('tr.jqgrow:visible:odd').addClass('myAltRowClass');
};
$("#tree").jqGrid({
    url: 'AdjacencyTreeAltRows.json',
    datatype:'json',
    mtype:'GET',
    colNames: ["ID", 'Description', "Total"],
    colModel: [
        {name:'id', index:'id', width: 1, hidden: true, key: true},
        {name:'desc', width:180, sortable:false},
        {name:'num', width:80, sortable:false, align:'center'}
    ],
    treeGridModel:'adjacency',
    height:'auto',
    //altRows: true,
    //altclass: 'myAltRowClass',
    rowNum: 10000,
    treeGrid: true,
    ExpandColumn:'desc',
    loadComplete: function() {
        var grid = this;
        resetAltRows.call(this);
        $(this).find('tr.jqgrow td div.treeclick').click(function(){
            resetAltRows.call(grid);
        });
        $(this).find('tr.jqgrow td span.cell-wrapper').click(function(){
            resetAltRows.call(grid);
        });
    },
    ExpandColClick: true,
    caption:"TreeGrid Test"
});


来源:https://stackoverflow.com/questions/6507094/is-it-possible-to-set-alternate-row-backcolor-on-a-jqgrid-treegrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!