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

1

2

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

Amaryllidaceous answered 28/6, 2011 at 13:20 Comment(0)
T
3

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

enter image description here

from the original tree

enter image description here

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"
});
Trieste answered 28/6, 2011 at 16:4 Comment(2)
that was my whole point as when you expand collapse you would need to reset the altRow colors. do you see any workaround s?Amaryllidaceous
thanks . . i am a bit concerned with performance of this but thanks for the updateAmaryllidaceous

© 2022 - 2024 — McMap. All rights reserved.