EasyUI Forum
November 01, 2025, 02:11:42 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How can I select a row in DataGrid GroupView after "clearSelections" [Solved]  (Read 20965 times)
cdy328
Newbie
*
Posts: 7


View Profile
« on: February 26, 2015, 01:55:28 AM »

I have already set "view:groupview",but the following codes doesn't work:
Thanks in advance Smiley.

$("#xxx").datagrid({
  ... ...
  onLoadSuccess:function(){
    var dg = $(this);
    checkedItems=dg.datagrid("options").checkedItems;

    for(var i=0;i<checkedItems.length;i++){
      // this row doesn't work
      dg.datagrid("checkRow",dg.datagrid("getRowIndex",checkedItems.id));
      ... ...
    }
}
« Last Edit: March 04, 2015, 11:08:31 PM by cdy328 » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 26, 2015, 07:07:34 AM »

Please check if you can get the row index correctly before calling the 'checkRow' method.
Code:
var index = dg.datagrid("getRowIndex",checkedItems.id);
alert(index)
dg.datagrid("checkRow", index);
Logged
cdy328
Newbie
*
Posts: 7


View Profile
« Reply #2 on: February 26, 2015, 06:34:46 PM »

1. sorry,the forum can't show "[]",my code is "checkedItems[ i ].id"
I don't know why,but I'm sure I can get the correct row index.
I select the first row,and the row index is "0".
2. I use the debugger "F12",find that the row can "select",but when
goes to "function initCss()",then the selected row turns to "unSelect"
3. I changed my code to this,even doesn't work,
I don't know what else affect this datagrid
    onLoadSuccess:function(){
        $(this).datagrid('selectRow',0);
        $(this).datagrid('checkRow',0);
        $(this).datagrid('checkRow',1);
    }   


« Last Edit: February 26, 2015, 06:43:55 PM by cdy328 » Logged
cdy328
Newbie
*
Posts: 7


View Profile
« Reply #3 on: February 27, 2015, 12:39:12 AM »

I have other codes,may be they are the reason that affect the above Smiley
because some other bugs,I must "clearSections" after "loadData".

I have tested that the datagrid's "onLoadSuccess" runs after the function "refreshAllTables()",
but the codes in "onLoadSuccess" doesn't work,
what else should I do, can I select a row after "clearSections" in function "refreshAllTables()" ?

    $(document).ready(function(){
        refreshAllTables();      
    });   

    function refreshAllTables(){
        ... ...
        ajax_request("/userworkspace/ajax_items_to_first_assign",{},function(result){
            $("#table_items_by_task").datagrid("loadData",result);            
            $("#table_items_by_task").datagrid("clearSelections");   
            ... ...      
        },0);
    }
« Last Edit: February 27, 2015, 12:43:07 AM by cdy328 » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: February 27, 2015, 01:10:28 AM »

Please refer to this example http://jsfiddle.net/0obkvg85/. It works fine.
Logged
cdy328
Newbie
*
Posts: 7


View Profile
« Reply #5 on: March 02, 2015, 09:41:53 PM »

Thanks.
1. The above code is well,but it have no "clearSelections",
and when I execute the function "clearSelections" in my function "refreshAllTables":
the above code can "check" a row,but can't "select" a now.
And I don't know when the "clearSelections" finished,does "clearSelections" have the function
like "onLoadSuccess"?
2. And I have another question,that I can't expand a group in "onLoadSuccess",
after "clearSelections"

onLoadSuccess:function(){
        $(this).datagrid('selectRow',0);
        $(this).datagrid('checkRow',0);
        $(this).datagrid('checkRow',1);

        for(var j=0;j<groupIndex.length;j++){
            $(this).datagrid('expandGroup',groupIndex[ j ]);
        }
    }  


function refreshAllTables(){
        ... ...
        ajax_request("/userworkspace/ajax_items_to_first_assign",{},function(result){
            $("#table_items_by_task").datagrid("loadData",result);            
            $("#table_items_by_task").datagrid("clearSelections");  
            ... ...      
        },0);
    }

3. I think that the execution sequence is "clearSelections"-"datagrid's onLoadSuccess",
but the result is not,how can I control after the "clearSelections" finished?
Expect you answer Smiley
« Last Edit: March 02, 2015, 09:43:39 PM by cdy328 » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #6 on: March 03, 2015, 08:56:57 AM »

Please notice your code:
Code:
            $("#table_items_by_task").datagrid("loadData",result);            
            $("#table_items_by_task").datagrid("clearSelections");   
You call 'clearSelections' method in finally. All your selected rows and checked rows will be cleared. Please call this method before selecting or checking rows. The updated example below shows how to do this.
http://jsfiddle.net/0obkvg85/1/
Logged
cdy328
Newbie
*
Posts: 7


View Profile
« Reply #7 on: March 03, 2015, 11:20:15 PM »

Thanks Smiley
It solved all the problems,and that method provide a new idea.
« Last Edit: March 04, 2015, 11:09:25 PM by cdy328 » 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!