Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
Getting list of all expanded rows so that I can open them later
posted

I need to be able to get a list of rows (client side) that have been expanded, so that when a user reloads the page, I can then expand them.

I've seen code to get the expanded rows, but trying to expand them again, doesn't seem to work. I'm missing something obvious I'm sure.

This is the code that I found (on the forum) to get all the expanded rows:

 arrExpandedRows = $("#gridRRA").igHierarchicalGrid("allChildren");

This is what I was using to expand the rows (found in the forum):

for (i = 0; i < arrExpandedRows.length; i++){
var rowDom = $("#" + arrExpandedRows[i].id);
$("#gridRRA").igHierarchicalGrid("expand",rowDom);
}

Parents Reply Children
  • 0
    Offline posted in reply to Vasya Kacheshmarova

    Hello  I tired your code but after refresh the grid ... row is getting collapse

    function SetExpandedRows(gridName, expandedRowIds) {
    debugger;
    //Loop through the array of row id's
    for (var i = 0; i < expandedRowIds.length; i++) {
    //Get the reference to the row in the grid
    //var gridRow = $("#" + gridName).igGrid("rowById", expandedRowIds[i]);

    expandedRowIds.push($(this).attr("data-id"))
    localStorage.setItem("id", JSON.stringify(expandedRowIds));
    console.log(localStorage);
    if (localStorage) {
    debugger;
    $.each(JSON.parse(localStorage.getItem("id")), function () {
    var newEl = $("tr[data-id='" + this + "']");
    debugger;
    $("#" + gridName).igHierarchicalGrid("expand", newEl);
    });

    }

  • 17590
    Offline posted in reply to Mike Burgess

    Hello Mike,

    Since you would like to implement persistence across data binding and browser refresh my suggestion is to use row ids (as you assumed) and keep these ids in the localStorage. Afterwards, when you would like to expand these rows again to retrieve the row by its id and pass it as parameter to expand method.For example:

    $("#btnGetExpandedRows").click(function(){
        expandedRows = $("#hierarchicalGrid tr[aria-expanded=true]");
        $.each(expandedRows, function(){
        dataIds.push($(this).attr("data-id"))
        });
        localStorage.setItem("id",JSON.stringify(dataIds) );
        })
         $("#btnExpandRows").click(function(){
        if(localStorage){
        $.each(JSON.parse(localStorage.getItem("id")), function(){
         var newEl = $("tr[data-id='" + this + "']");
         $("#hierarchicalGrid").igHierarchicalGrid("expand", newEl);
        });
        }
        else{
         alert("Expand any row");
        }
        });

     I am attaching ,y modified sample for your reference.

    Please let me know if you have any additional questions regarding this matter.

    igHierarachicalgridExpandPreviouslyExpandedRowsPersistance.zip