Ticket T103081
Visible to All Users

How to implement "Select All" checkbox which selects only rows with a visible SelectCheckBox?

created 11 years ago

I have an ASPxGridView that has a SelectCheckBox as the first column.  Some of the CheckBoxes are hidden based on some data.  The problem is when I click the Select All checkbox, it selects all the rows instead of only the ones that have checkboxes.  How can I remedy this problem?

Here is my markup:

ASPx
<dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="-1" Width="32"> <HeaderTemplate> <dx:ASPxCheckBox ID="SelectAllCheckBox" runat="server" ToolTip="Select/Unselect all rows on the page" ClientSideEvents-CheckedChanged="function(s, e) { grid.SelectAllRowsOnPage(s.GetChecked()); }" /> </HeaderTemplate> <HeaderStyle HorizontalAlign="Center" /> </dx:GridViewCommandColumn>

Here is my code for hiding the checkboxes:

Visual Basic
Protected Sub grid_CommandButtonInitialize(sender As Object, e As ASPxGridViewCommandButtonEventArgs) Handles grid.CommandButtonInitialize If e.VisibleIndex = -1 Then Return End If Dim fieldValue As Object = grid.GetRowValues(e.VisibleIndex, "StatusCode") If e.ButtonType = ColumnCommandButtonType.SelectCheckbox Then If fieldValue = "S" Then e.Visible = True Else e.Visible = False End If End If End Sub

Answers approved by DevExpress Support

created 11 years ago

Hello,

I recommend you use the ASPxGridView - How to select all rows except disabled rows on the client side example for your scenario.
Please let me know if you need further assistance.

    Show previous comments (4)
    Lanette (DevExpress Support) 11 years ago

      Thank you for informing us that the problem is resolved.
      Feel free to contact us in case of any further difficulties.

      SH SH
      Saied Hassaninia 4 11 years ago

        OK, I just tested it the following script in all browsers, but I get "Error: Object doesn't support property or method 'indexOf' in Internet Explorer 11.  It works on my local machine when I run it in IE where I am using DevExpress 12.1.4.0
        <script type="text/javascript">
               function OnAllCheckedChanged(s, e) {
                   grid.PerformCallback(s.GetChecked());
               }
               function OnPageCheckedChanged(s, e) {
                   var indexes = grid.cpIndexesUnselected;
                   var topVisibleIndex = grid.GetTopVisibleIndex();
                   if (s.GetChecked()) {
                       //Select All Rows On Page();
                       for (var i = topVisibleIndex; i < topVisibleIndex + grid.cpPageSize; i++) {
                           if (indexes.indexOf(i) == -1) //ERROR Happens HERE
                               grid.SelectRowOnPage(i, true);
                       }
                   }
                   else
                       //Deselect All Rows On Page();
                       for (var i = topVisibleIndex; i < topVisibleIndex + grid.cpPageSize; i++) {
                           if (indexes.indexOf(i) == -1) //ERROR Happens HERE
                               grid.SelectRowOnPage(i, false);
                       }
               }
               function setGridHeaderCheckboxes(s, e) {
                   //cbAll
                   var indexes = grid.cpIndexesSelected;
                   cbAll.SetChecked(s.GetSelectedRowCount() == Object.size(indexes));
                   //cbPage
                   var allEnabledRowsOnPageSelected = true;
                   var indexes = grid.cpIndexesUnselected;
                   var topVisibleIndex = grid.GetTopVisibleIndex();
                   for (var i = topVisibleIndex; i < topVisibleIndex + grid.cpPageSize; i++) {
                       if (indexes.indexOf(i) == -1)
                           if (!grid.IsRowSelectedOnPage(i)) allEnabledRowsOnPageSelected = false;
                   }
                   cbPage.SetChecked(allEnabledRowsOnPageSelected);
               }
               function OnGridEndCallback(s, e) {
                   setGridHeaderCheckboxes(s, e);
               }
               function OnGridSelectionChanged(s, e) {
                   setGridHeaderCheckboxes(s, e);
               }
               Object.size = function (obj) {
                   var size = 0, key;
                   for (key in obj) {
                       if (obj.hasOwnProperty(key)) size++;
                   }
                   return size;
               };
           </script>

        Lanette (DevExpress Support) 11 years ago

          Hello,

          To avoid discussing multiple topics in this thread, I have extracted your original inquiry to a separate ticket created on your behalf: T108126: An "Object doesn't support property or method 'indexOf'" exception is thrown on "Select All" checkbox click in IE11. For quick and efficient responses, we kindly request that future tickets cover one issue at a time. Your time and cooperation are appreciated.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.