This is a migrated thread and some comments may be shown as answers.

[Solved] GridClientSelectColumn Handler does not work

2 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kai
Top achievements
Rank 2
Kai asked on 11 Mar 2013, 03:20 PM

Hi all,

I need to do some backend tasks when the user clicks the 'Select All'-Checkbox at the top of my grid. I followed this approach and it works fine: http://www.telerik.com/community/forums/aspnet-ajax/grid/gridclientselectcolumn-select-all.aspx#1469954

 

In the backend I then select ALL documents on ALL pages. I go to page 2 and all documents are selected as expected. But then I want to deselect all, and this does not work, because the deselect-click is not recognized on first try. Then you have to select all again and then deselect, on the second try it works fine.

 

I think the problem is caused by the auto-checked 'Select all'-Checkbox if all docs on current page are selected:

  1. I'm on page 1.
  2. I click 'Select all'.
  3. Handler is fired. In the backend I mark all documents as selected.
  4. I switch to page 2. All documents are selected as expected. BUT also the 'Select all'-Button in the Header is checked.
  5. I unselect the 'Select all' Button on the header, but the handler is not fired.
  6. I select the 'Select all' button on the header, now the hanlder is fired and all docs on all pages are marked as selected.
  7. I unselect the 'Select all' Button on the header and now the handler is fired, deselecting all docs on all pages.

So the problem is in step 5. I guess this is because by default the 'Select all' is not checked, but after all docs are displayed and the grid notices that all are checked, the 'Select all' is also checked automatically, but without notifying the backend handler. So when I uncheck the 'Select all' checkbox (step 5), the handler does not fire because the checkbox is 'still unchecked' (as the backend did not know that the grid checked the 'select all' checkbox in the meantime).

Might this be the reason? And if so, is there a workaround somehow? For example by disabling the 'Select all' checkbox to be checked if all docs on the page are checked? I've read in another posting that this is the expected behaviour but maybe there is chance to remote it?

Many thanks in advance!

2 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 14 Mar 2013, 11:39 AM
Hello Kai,

Yes you are right for the reason. The checkbox is unchecked by default and some JavaScript run client side to check if all checkboxes are checked and change it's status.

You can do 2 workarounds. First one is to handle client side the checking, by attaching JavaScript to the CheckBox, and to do Ajax call or postback manually.
Second one is when you attaching the handler, to check the checkbox server side, if you are sure that all items are checked. For example handle the:
chkSelectAll_CheckedChanged, and rise some flag in the page. Then during the ItemCreated (which will fire second time for your items, it fires one during the load and one after the paging), set the CheckBox to checked. Then on the second PostBack the handler will be fired on uncheck.


Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Kai
Top achievements
Rank 2
answered on 15 Mar 2013, 12:34 PM
Hi Vasil,
I followed your second tip and it seems to work fine.
Many thanks!!
Tags
Grid
Asked by
Kai
Top achievements
Rank 2
Answers by
Vasil
Telerik team
Kai
Top achievements
Rank 2
Share this question
or