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

CheckAll Functionality with pagination in RadGrid

3 Answers 198 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chamara
Top achievements
Rank 1
Chamara asked on 26 Oct 2011, 03:53 AM
I using following code to implement checkAll functionality using a header template checkbox.it works fine for the current page when pagination is enabled.i need to check all checkboxs in all the pages


 function CheckHeaderCheckBoxIfNeeded(radGrid) {
                var checkHeaderCheckBox = true;
                var dataItems = radGrid.get_masterTableView().get_dataItems();
              
                for (var i = 0; i < dataItems.length; i++) {
                    var dataItem = dataItems[i];
                    var row = dataItem.get_element();
                    var ckeckBox = row.children[0].children[0];
                    if (!ckeckBox.checked) {
                        checkHeaderCheckBox = false;
                    }
                }


                SelectCheckBox(checkHeaderCheckBox);
            } 

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 26 Oct 2011, 11:31 AM

Hello Chamara,

When the grid is in paging mode only the items for the current page are retrieved - there are no items in memory.
Additionally If you want to operate with all records from the source when the grid paging is enabled, reference directly the data from the underlying data source to process further operations over it.

The other solution is to disable temporary the paging feature of the control.
You have to set the AllowPaging property of the grid to false at a certain stage of the lifecycle and rebind the control invoking its Rebind() method, then traverse all items in it. When you are done with this task, set the AllowPaging property back to true and rebind the grid to enable the paging feature again.

Pavlina
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
Chamara
Top achievements
Rank 1
answered on 27 Oct 2011, 06:10 PM
I need to do this javascript code because there are nearly 10000 records already, on my grid and in the header checkbox event i'm already running some other code also.if i implement your second solution in server side it'll make the response very slow.so can you provide me a code sample to implement this in client side?  
0
Jayesh Goyani
Top achievements
Rank 2
answered on 28 Oct 2011, 08:12 AM
Hello,

<script type="text/javascript">
 var selected = {};
            function RadGrid1_RowSelected(sender, args) {
                var StudentId = args.getDataKeyValue("StudentId");
                if (!selected[StudentId]) {
                    selected[StudentId] = true;
                }
            }
            function RadGrid1_RowDeselected(sender, args) {
                var StudentId = args.getDataKeyValue("StudentId");
                if (selected[StudentId]) {
                    selected[StudentId] = null;
                }
            }
            function pageLoad(sender, args) {
                var dataItems = $find('<%=RadGrid1.ClientID %>').get_masterTableView().get_dataItems();
                for (var i = 0, j = dataItems.length; i < j; i++) {
                    var item = dataItems[i];
                    if (selected[item.getDataKeyValue("StudentId")]) {
                        item.set_selected(true);
                    }
                }
            }
 </script>
<telerik:RadGrid ID="RadGrid1" runat="server">
 <MasterTableView  ClientDataKeyNames="StudentId">
   
 <ClientSettings   Selecting-AllowRowSelect="true" EnableRowHoverStyle="true">
                        <ClientEvents OnRowSelected="RadGrid1_RowSelected" OnRowDeselected="RadGrid1_RowDeselected" />
                    </ClientSettings>
   
                </telerik:RadGrid>

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
General Discussions
Asked by
Chamara
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Chamara
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or