EasyUI Forum
March 04, 2024, 02:28:57 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: .treegrid('getRowIndex', row['id']) not working. Always returns a -1  (Read 1309 times)
larryclyons
Newbie
*
Posts: 9


View Profile Email
« 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.
« Last Edit: August 10, 2023, 12:10:46 PM by larryclyons » Logged
jarry
Administrator
Hero Member
*****
Posts: 2260


View Profile Email
« Reply #1 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']);
Logged
larryclyons
Newbie
*
Posts: 9


View Profile Email
« Reply #2 on: August 11, 2023, 05:14:10 AM »

Thanks jarry that worked. Your help is much appreciated
« Last Edit: August 11, 2023, 05:23:59 AM by larryclyons » Logged
larryclyons
Newbie
*
Posts: 9


View Profile Email
« Reply #3 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.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2260


View Profile Email
« Reply #4 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.
Logged
larryclyons
Newbie
*
Posts: 9


View Profile Email
« Reply #5 on: August 17, 2023, 08:30:37 AM »

thanks Jarry I'll give that a try. Much appreciated.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!