EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: larryclyons on August 10, 2023, 12:00:51 PM



Title: .treegrid('getRowIndex', row['id']) not working. Always returns a -1
Post by: larryclyons on August 10, 2023, 12:00:51 PM
Hi I am trying to use the getRowIndex to get the correct index of a particular row in a tree grid. However no matter what row is selected, if it's the first one, the 2nd or the 20th, it always returns a -1.

Here's the code I use this to refresh the treegrid.
Code:
       
function refreshGrid(grid_id){
     var row = $('#' + grid_id).treegrid('getSelected');
     console.log(row);
     if(row){
           var rowIndex = $('#' + grid_id).datagrid('getRowIndex', row['id']);
           
           console.log(rowIndex); return false;
         
          $('#' + grid_id).treegrid('refresh',row['id']);
          $('#' + grid_id).treegrid('scrollTo',rowIndex);
          $('#' + grid_id).treegrid('selectRow',rowIndex);
          $('#' + grid_id).treegrid('highlightRow',rowIndex);
     }
}

 And here is a sample of the JSON being returned from the server:
Code:
[{"work_release_id":213,"poc_profile_id":201,"has_attach":"true","lvl":1,"can_add_pl":"true","col8":"NaN","col7":" $.00","col6":"","state":"closed","can_edit_header":"true","col5":"New Formulation In Process","appr_doc_id":0,"col4":"09/20/2023","col3":"08/10/2023","col2":" 700.00","col1":"ASO-0213-000 VI 2 ","wr_rev_id":235,"can_edit_title":"true","can_generate_afa":"false","can_read_formulation":"true","poc_name":"ABC DEF","can_cancel_formulation":"false","id":"1_213","can_return_to_contractor":"false","can_submit_to_cnt":"true","can_delete_formulation":"true","can_init_revision":"false","can_read_approved_cost_structure":"false","doc_set_id":4390,"can_display_graph":"true","Level":1,"can_cancel_revision":"false","can_unsubmit_to_cnt":"false","can_email_poc":"false","form_doc_id":4339,"is_complete":1,"can_approve_wp":"false","lk_status_id":100,"can_change_wr_notes":"true","wrname":"ASO-0213-000 VI 2 (ABC DEF)","can_paste_pl":"false","can_change_wrpoc":"false","can_send_file_to_contractor":"false","can_unsign_wp":"false"},{"work_release_id":212,"poc_profile_id":173,"has_attach":"true","lvl":1,"can_add_pl":"true","col8":"NaN","col7":" $.00","col6":"","state":"closed","can_edit_header":"true","col5":"New Formulation In Process","appr_doc_id":0,"col4":"08/14/2024","col3":"09/21/2023","col2":" 3000.00","col1":"AWA-0212-000 impact test (GHI JKL)","wr_rev_id":234,"can_edit_title":"true","can_generate_afa":"false","can_read_formulation":"true","poc_name":"GHI JKL","can_cancel_formulation":"false","id":"1_212","can_return_to_contractor":"false","can_submit_to_cnt":"true","can_delete_formulation":"true","can_init_revision":"false","can_read_approved_cost_structure":"false","doc_set_id":4363,"can_display_graph":"true","Level":1,"can_cancel_revision":"false","can_unsubmit_to_cnt":"false","can_email_poc":"false","form_doc_id":4268,"is_complete":1,"can_approve_wp":"false","lk_status_id":100,"can_change_wr_notes":"true","wrname":"AWA-0212-000 impact test (GHI JKL)","can_paste_pl":"false","can_change_wrpoc":"false","can_send_file_to_contractor":"false","can_unsign_wp":"false"}]
[\code]

Any help would be appreciated.


Title: Re: .treegrid('getRowIndex', row['id']) not working. Always returns a -1
Post by: jarry on August 11, 2023, 12:13:55 AM
The row index doesn't valid in the treegrid component. Please pass the row id instead.
Code:
$('#' + grid_id).treegrid('refresh',row['id']);
$('#' + grid_id).treegrid('scrollTo',row['id']);
$('#' + grid_id).treegrid('selectRow',row['id']);
$('#' + grid_id).treegrid('highlightRow',row['id']);


Title: Re: .treegrid('getRowIndex', row['id']) not working. Always returns a -1
Post by: larryclyons on August 11, 2023, 05:14:10 AM
Thanks jarry that worked. Your help is much appreciated


Title: Re: .treegrid('getRowIndex', row['id']) not working. Always returns a -1
Post by: larryclyons on August 14, 2023, 12:47:13 PM
Thanks jarry. That worked, but only for the first level. When I try it with the subsequent levels, while the row in question is selected, the parent row is not expanded. Here's what I've tried:
Code:
function refreshGrid(grid_id){
    var grid = '#' + grid_id;
    var row = $(grid).treegrid('getSelected');
    if(row){
        var grid_level = $(grid).treegrid('getLevel', row['id]'])
        $(grid).treegrid('reload');
        if (grid_level ==0){
            $(grid).treegrid('scrollTo',row['id']);
            $(grid).treegrid('selectRow',row['id']);
            $(grid).treegrid('highlightRow',row['id']);
        } else if (grid_level == 1){
            // get the parrent node and id
            var parentNode = $(grid).treegrid('getParent', row['id']);
            var parent_id = parentNode['id'];
           
            // scroll to the parent node, expand it and select the row.
            $(grid).treegrid('scrollTo',parentNode['id']);
            $(grid).treegrid('expand', parentNode['id']);
            $(grid).treegrid('select', row['id']);
        }
    }
}

What happens is that the grid is reloaded, but the parent node is collapsed. When I expand it, the row in question is selected. I am not sure what the issue is in this case, so any help would be appreciated.


Title: Re: .treegrid('getRowIndex', row['id']) not working. Always returns a -1
Post by: jarry on August 17, 2023, 01:20:50 AM
The 'reload' method accepts the 'id' parameter. If the 'id' value is missing, the treegrid will reload the root node. If the 'id' value is set, the treegrid will reload the specified node.

Code:
$(grid).treegrid('reload', idvalue);

Please try to pass the node's id value to the 'reload' method if you want to reload that node.


Title: Re: .treegrid('getRowIndex', row['id']) not working. Always returns a -1
Post by: larryclyons on August 17, 2023, 08:30:37 AM
thanks Jarry I'll give that a try. Much appreciated.