Ticket T153324
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

GridView - Custom Binding - The GetSelectedFieldValues method returns values from the current page only

GridView Custom Binding with checkboxes not working well

created 10 years ago

Hi,
I have problem with my checkboxes in MVC application when I'm using custom binding.

I tried to go through demo on this link but without success: https://demos.devexpress.com/MVCxGridViewDemos/DataBinding/SimpleCustomBinding

In attachment I'm including short video for better description of my problem and also my test project .

Thank you for help.

Answers approved by DevExpress Support

created 10 years ago

Hi,

Thank you for your sample. I have examined it and concluded that this behavior is expected. When custom binding is used, the grid receives the information about the current page only. We have already answered a similar question in the context of the Q498407: GridView - Custom Binding - The GetSelectedFieldValues method returns values from the current page only ticket. Thus, you might need to emulate the required selection behavior in this mode manually. For instance, to select all rows, you can handle the PreRender and BeforeGetCallbackResult events and put the following code into them:

C#
var grid = sender as MVCxGridView; grid.Selection.SelectAll();

Of course, this is only an emulation because the SelectAll method will select only current page rows. However, this approach will create a visual effect like all rows are selected, because the BeforeGetCallbackResult event should be called every time the page index is changed.

See Also:
T139797: GridView- Custom Data Binding - The client-side GetSelectedFieldValues method returns a wrong result after the CustomBindingFiltering action

Thanks,
Alessandro.

    Show previous comments (1)
    Alessandro (DevExpress Support) 10 years ago

      Hi,

      Yes, you are right. GridView maintains selected keys to store selection state between callbacks. In case of a custom binding mode, not all keys are available because data in this mode is fetched from the server in small portions. That is why it is not easy to implement the "Select All" functionality. I can only suggest that you "emulate" this feature. For instance, handle the PreRender and BeforeGetCallbackResult events as I illustrated in my original answer. To pass the "Select All" state between the client and server, use the approach from the following help sections:

      Passing Values to a Controller Action through Callbacks
      How to: Access Server Data on the Client Side

      For instance, check the E5125 - GridView - How to implement optimistic concurrency for the update/delete operations code example, where we have illustrated this approach.

        Hello Alessandro,
        I understand how your grid works and also understand how to emulate this "Select All" behavior.
        For now we have this solution:
        When "Select All" checkbox is selected, we send callback where we store this selection value to the session, then in BeforeGetCallbackResult set the checkbox state and select all page according session value ect…
        But we are only able to emulate the state of the checkbox not the state of selection… Let's imagine situation we select all, then unselect first page, go the next page and now we want to send all selected keys to server for some action (e.g. remove selected). It means we need to send keys of all records except first page. We are not able to find out what keys are selected and even the state of the select all session can't help us.
        I think only one solution is somehow insert all keys to grid internal collection when select all checkbox is checked but I don't know if this is possible. I think "Select All" option is kind of commonly used feature so maybe feature request to be able insert selected keys to the grid would be great.
        Thanks a lot for any help with this tricky issue.
        Anton

        Alessandro (DevExpress Support) 10 years ago

          Hi,

          I have discussed this scenario with our developers and we concluded that it is impossible to support the Select All feature  (according to the default selection implementation) in custom binding. The reason is that not all data is fetched in this mode. Thus, it is unclear which row key should be added to the selection dictionary. We will update our documentation accordingly (see T158326: Documentation - Add a note that the "Select All" feature is not supported in Custom Binding and Server modes). So, the only appropriate approach is to "emulate" this feature by using the technique I illustrated above. However, if you wish to select all rows and then unselect some rows on a page as you described above, you probably need to manipulate the keys of all rows. This requires requesting all data rows from the database server. Thus, you might lose the advantage of custom binding. At present, I believe that there are two possible ways:

          1. Keep using custom binding with the capability to select all rows or implement it partially (without the capability to select all rows and then unselect specific rows only) by using the "emulation" technique.

          2. Use the full-featured Select All capability (GridViewCommandColumn.SelectAllCheckboxMode) in the regular binding mode.

          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.