Skip to content

Feature - provide prepopulated array of selected rows on initialization. #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JBMiller
Copy link

@JBMiller JBMiller commented Feb 27, 2023

Related to Issue #62

@JBMiller JBMiller marked this pull request as ready for review February 27, 2023 16:16
@mpryvkin
Copy link
Member

mpryvkin commented Mar 8, 2023

Thank for your submission!

In general, implementing checkboxes with server-side processing is not a trivial matter because only one page data is available at one time.

Where are you planning to get data for initialSelectionArray parameter? Since the data comes from the server, I assume you would want checked items IDs to be coming from the server as well. However in your implementation it is provided on the client-side.

@JBMiller
Copy link
Author

JBMiller commented Mar 9, 2023

Fair point. I'll provide more context.

I work in ASP.NET MVC. The context is that I have an admin panel form that creates/edits a thing (let's call it a Special Offer/Promotion) and that thing can be associated to multiple other things (let's say a product. There is a database table of products and this offer can apply to several of them). When loading the form to edit an Offer, it is going to also include a paginated, searchable, server-side-ajax-powered table of products that you can select from, that indicates which products the offer applies to. When editing, however, preexisting associations should be checked off initially, to give the admin user the option to dissociate (uncheck) or to simply see what is already associated while making changes.

Where are you planning to get data for initialSelectionArray parameter?

From the server side, which is passed to the front end (a cshtml file in this case) which can accept a model (a data object) from the server that aids in crafting the html, css and javascript that is ultimately rendered to the end-user as the initial page-load. In cshtml, it will look something like this:

'initialSelectionArray': [ @Html.Raw(string.Join(",", Model.PreselectedIdArray.Select(id => "'" + id + "'"))) ]

Which, given the PreselectedIdArray contained values [34,35], it would render as this:

'initialSelectionArray': [ '34', '35' ]

Here is a more conclusive example:

$('#example').DataTable({
    'columnDefs': [
        {
            'targets': 0,
            'checkboxes': {
                'selectRow': true,
                'initialSelectionArray': [ '34', '35' ]
            }
        }
    ],
    // ...
});

I believe other frameworks have this capability, however, I cannot personally attest to them as I solely program in ASP.NET MVC C#.

Since the data comes from the server, I assume you would want checked items IDs to be coming from the server as well. However in your implementation it is provided on the client-side.

My use-case does not cover the case where the paginated data from the ajax request dictates which rows should be selected. Having the server dictate which rows should be selected will clash with the client side changes the admin user would be trying to make anytime the table page is refreshed. Thus, the server-side pagination should never send back which rows should be selected. At least within my use-case, deciding which rows should be selected should be a separate data source that applies its information only on initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants