EasyUI Forum
May 04, 2024, 05:06:55 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: Datagrid checkbox questions  (Read 10959 times)
siccak
Newbie
*
Posts: 5


View Profile Email
« on: October 15, 2015, 11:30:50 AM »

Hello,

I have two questions about using datagrid with checkbox column.

1. check All button

I am using my datagrid with pagination and if I click check all button then only rows on first page are selected. Is there any way how to check rows on all pages?

2. hiding checkbox and getChecked method

Is there any way how to conditionally hide checkbox on row, based on some formula or anything else? I am achieving this by using rowStyler, but it has some drawbacks. getChecked method is returning values from all checkboxes (not respecting hidden or disabled checkboxes) and this will be more complicated if my first question will be answered.

Thank you, Sicco
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: October 15, 2015, 08:09:10 PM »

Click the check button on column header, only the current page rows are checked. You can custom this behavior by overriding the 'onCheckAll' and 'onUncheckAll' event handlers.
Code:
$('#tt').datagrid({
    url:'test.php',
    pagination:true,
    idField:'itemid',
    onCheckAll:function(){
        var state = $(this).data('datagrid');
        $.ajax({
            url:'getallrows.php',
            type:'POST',
            dataType:'json',
            success:function(data){
                state.checkedRows = data.rows;
                state.selectedRows = data.rows;
            }
        })
    },
    onUncheckAll:function(){
        var state = $(this).data('datagrid');
        state.checkedRows = [];
        state.selectedRows = [];
    }
});
Logged
siccak
Newbie
*
Posts: 5


View Profile Email
« Reply #2 on: October 23, 2015, 04:38:31 AM »

Thank you jarry, it works.

And about my second question, it seems I am out of luck.

Siccak
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: October 24, 2015, 05:36:01 AM »

To hide the checkbox conditionally, define the 'styler' or 'rowStyler' function to achieve this functionality. Please refer to the code below.
Code:
<style>
  .dg-nocheck .datagrid-cell-check{
    display: none;
  }
</style>
<th data-options="field:'ck',checkbox:true,
    styler:function(index,row){
      if (row.listprice>40){
        return {class:'dg-nocheck'};       
      }
    }"></th>
Logged
lloyd
Newbie
*
Posts: 29


View Profile Email
« Reply #4 on: October 26, 2015, 09:21:20 AM »

I was going to ask the same (1. check All button) question.
I would suggest doing it this way as the pagination function already has all the data. Wink

Code:
        tg.treegrid({
            onCheckAll: function() {
                var allRows = $(this).treegrid('getAllRows');
                var state = $(this).data('datagrid');
               
                state.checkedRows = allRows;
            },
            onUncheckAll: function() {
                var state = $(this).data('datagrid');
                state.checkedRows = [];
            }
        }).treegrid('clientPaging');
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!