Search code examples
jqueryjqgridtreegrid

expandRow method not working[jqgrid TreeGrid]


var record = jQuery("#gridTable").jqGrid("getRowData",1); 
$("#gridTable").jqGrid('expandRow', record);

above code does not work. value of record is as below

Object {id: "1", isLeaf: "false", stepNo: "1", stepDescription: "Add New Material", expectedResult: ""…}
actualResult :"All OK"
executionTime : "1.587"
expanded : "false"
expectedResult : ""
icon : ""
id : "1"
isLeaf : "false"
level : "0"
loaded : "true"
parent : ""
status :  "Done"
stepDescription : "Add New Material"
stepNo : "1"

but when below code is used to expand row it does work... only difference that I see is some non quoted numeric values.

var allRowsInGrid = $('#gridTable').jqGrid('getGridParam','data');
$("#gridTable").jqGrid('expandRow', allRowsInGrid[record.id-1]);

Object {id: 1, isLeaf: false, stepNo: 1, stepDescription: "Add New Material", expectedResult: undefined…}
actualResult : "All OK"
executionTime : "1.587"
expanded : false
expectedResult : undefined
icon : undefined
id : 1
isLeaf : false
level : "0"
loaded : true
parent : ""
status : "Done"
stepDescription : "Add New Material"
stepNo : 1
_id_ : "1"

I really need to use 1st method and also understand the issue here, thanks in advance


Solution

  • The usage of the object returned from getRowData as the parameter of expandRow is wrong. TreeGrid saves the data locally in data array. The parameter of expandRow should be element from the local data. Thus you should fix the code

    var rowid = "1",
        record = jQuery("#gridTable").jqGrid("getRowData", rowid); 
    $("#gridTable").jqGrid("expandRow", record);
    

    to

    var rowid = "1",
        record = jQuery("#gridTable").jqGrid("getLocalRow", rowid); 
    $("#gridTable").jqGrid("expandRow", record);