Select all checkbox not working for non DOM sourced data

Select all checkbox not working for non DOM sourced data

ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

First, thanks for the great work you've been doing.

Whenever the table's data is sourced from any place other than the DOM, the select all checkbox does not work.

In the test case below, when the select all checkbox is clicked, only the rows on the first page are selected. Also, when you select a row on the current page and press shift+click on a select checkbox on another page the same issue occurs again.

But when you first visit all the pages and then click on the select all checkbox, everything seems to work as it should.

Lastly, since the select checkbox is an actual checkbox now, can you remove the default styles so that it will use the default styles of the app or is there a way to remove the class dt-select-checkbox from the select checkboxes.

Test Case: https://live.datatables.net/kasidece/1/edit

Thanks

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin
    edited March 29 Answer ✓

    Good one! Thanks for the test case. It isn't immediately apparent to me what is going wrong there. I'll try to look into it next week, but I'm travelling around a fair bit then, so it might be the following week I'm afraid.

    edit It seems like it is related to deferRender. Disable that and it works fine (it is enabled by default in DataTables 2). I had thought I'd handled that in the code, but apparently not correctly!

    Allan

  • ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

    Thanks @allan it works after setting deferRender to false. The issue is, I have about 20,000 rows in the table so changing it to false negatively affects the performance. Is there a way to get it to work without setting deferRender to false?

    Thanks

  • setwebmastersetwebmaster Posts: 78Questions: 5Answers: 0

    Just stumbled upon the same problem, what are the chances that it's been reported today :smile:

    I disabled deferRender for now and it also seems to work on my side but it does seem to affect performance a little (my pc is a beast so not much problem here but I can guess some users might feel it more).

    Thanks for the awesome project no matter what! It's been a pleasure to work with it in the last years :) (the migration to version 2 was not that trivial considering I had heavily customized DT in my app, but that's a "me" problem ahah :P)

  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin

    I've just committed the fix. It will be in the nightly build soon, and it will be in the Select 2.0.1 release (that may or may not happen next week - I'll try to get it done, but circumstances might not make it easy!).

    Thanks for the awesome project no matter what!

    Thank you! :) That means a lot.

    Allan

  • ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

    Great. Thank you very much @allan

  • ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

    @allan thanks for the quick fix.

    Now with deferRender enabled, when the select all checkbox is clicked, all the rows get selected as it should but only the checkboxes of the rows that are already created (mostly rows on the first page), get checked. Also when you select all, you can't deselect all.

    Kindly take a look at the test case below.
    Thanks again.

    Test Case: https://live.datatables.net/kasidece/4/edit

  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin
    Answer ✓

    but only the checkboxes of the rows that are already created (mostly rows on the first page), get checked.

    That is correct. I can't check a checkbox that hasn't been created yet :). Use table.rows({selected: true})... to get the rows which are selected, regardless of checkbox state.

    If you do need to have the actual checkboxes, then you have no choice but to disable deferRender.

    Also when you select all, you can't deselect all.

    Doh! I can't believe I didn't check that - sorry! I've fixed it now and the nightly will rebuild soon.

    Allan

  • ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

    Thanks for the fix.

    I can't check a checkbox that hasn't been created yet

    I guess I will enable deferRender and then use createdRow to manually check the checkbox if the row is selected.

    Thanks again @allan

  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin

    The checkbox should get checked if the row has been created (which it will be if deferRender is disabled). Is that not happening? You shouldn't need to use createdRow to do this.

    Allan

  • ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

    When deferRender is disabled everything works perfectly. But I'm dealing with large data so I can't disable it.

    I solved it by enabling deferRender, and then used createdRow to programmatically check the checkboxes if their parent rows are selected.

    Option 2 Since I'm using table.rows({selected: true}) to select selected rows, I may switch back to fake checkboxes until I get a better solution that support actual checkboxes and enabled deferRender.

    Thanks

  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin

    I'm not understanding I'm afraid. As far as I can see, with the nightly build, the real checkboxes are working with deferRender enabled. Is that not the case for you? For example, use the check all header, and then go to the second page and it will show the checkboxes and rows on the second page as checked / selected. Is that not the case for you?

    Allan

  • ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

    For example, use the check all header, and then go to the second page and it will show the checkboxes and rows on the second page as checked / selected. Is that not the case for you?

    Unfortunately when I click on the select all checkbox in the header and then go to the second page, the rows on the second page get selected but the checkboxes are not checked.

    Please take a look at this test case: https://live.datatables.net/qesehomi/1/edit
    Thanks

  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin

    Yes, sorry. That is an error. I will get that sorted out.

    Allan

  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin

    This commit should sort it out!

    Allan

  • ruleboy21ruleboy21 Posts: 14Questions: 3Answers: 0

    Great. Thank you very much @allan

Sign In or Register to comment.