gyrocode / jquery-datatables-checkboxes

Checkboxes is an extension for the jQuery DataTables library that provides universal solution for working with checkboxes in a table.
https://www.gyrocode.com/projects/jquery-datatables-checkboxes/
MIT License
150 stars 61 forks source link

All checkboxes deselected after table.ajax.reload #133

Closed shorenaa closed 2 years ago

shorenaa commented 3 years ago

I am using the latest version.

Unfortunately, state saving is not working as expected. After selecting the checkboxes, if I click on the button that performs table.ajax.reload, the selected checkboxes get unselected. However, the rest (sorting, paging, etc) stays kept.

Please, help me... I have spent hours trying to find an answer but in vain.

Regards

mpryvkin commented 3 years ago

Most likely the issue is that your column containing checkboxes has no data. In order to have checkboxes state saved, column containing checkboxes must have unique values.

Please see this example for code and demonstration.

Also there is State saving page demonstrating other related options.

If that doesn't solve you issue, please create an example on jsFiddle reproducing it. Thanks!

shorenaa commented 3 years ago

Hello,

Thank you very much for your email

I have defined the data for the columns. Please, have a look at the screenshot. Below the screenshot, you can see the JS Code. However, despite all my efforts, the problem still exists.

[image: image.png]

The JS Code is as follows:

columns: [ { data: "1" }, { data: "2" }, { data: "3" }, { data: "4" }, { data: "5" }, { data: "6" }, { data: "7" }, { data: "8" }, { data: "9"}, { data: "10" } ],

   'columnDefs': [
     {
        'targets': 0,
        'checkboxes': {
           'selectRow': true,
           'stateSave': true
        }
     }
  ],
  'select': 'multi',
  'order': [[1, 'asc']],
     stateSave: true,

On Thu, Oct 7, 2021 at 4:13 AM Michael Ryvkin @.***> wrote:

Most likely the issue is that your column containing checkboxes has no data. In order to have checkboxes state saved, column containing checkboxes must have unique values.

Please see this example https://jsfiddle.net/epLxw0zb/ for code and demonstration.

Also there is State saving https://www.gyrocode.com/projects/jquery-datatables-checkboxes/examples/basic/state-saving/ page demonstrating other related options.

If that doesn't solve you issue, please create an example on jsFiddle reproducing it. Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gyrocode/jquery-datatables-checkboxes/issues/133#issuecomment-937339468, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADIIQ7BIMYJCJKOHAM4AEY3UFTQ37ANCNFSM5FP26EIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Kind Regards,

George Lekiashvili

*Tel: +995551656598 | Email: @. @.>*

shorenaa commented 2 years ago

UPDATE!

I have solved the issue by adding the following array >> array( 'db' => 'users.id', 'dt' => 'DT_RowId', 'field' => 'id' )

Since the 'DT_RowId' is essential as it defines the unique value of each column, we have to make sure that it is included in the PHP script. (In my case I am using SSP.class)

$columns = array( //array( 'db' => 'users.email'), array( 'db' => 'users.id', 'dt' => 'DT_RowId', 'field' => 'id' ), array( 'db' => 'users.operator', 'dt' => 0, 'field' => 'operator' ), array( 'db' => 'users.operator', 'dt' => 1, 'field' => 'operator' ), array( 'db' => 'users.email', 'dt' => 2, 'field' => 'email' ), array( 'db' => 'users.mobile', 'dt' => 3, 'field' => 'mobile' ), array( 'db' => 'users.pin', 'dt' => 4, 'field' => 'pin' ), array( 'db' => 'users.threshold', 'dt' => 5, 'field' => 'threshold' ), array( 'db' => 'users.password', 'dt' => 6, 'field' => 'password' ), array( 'db' => 'users.name', 'dt' => 7, 'field' => 'name' ), array( 'db' => 'users.surname', 'dt' => 8, 'field' => 'surname' ), array( 'db' => 'users.date_last', 'dt' => 9, 'field' => 'date_last' ),

);

Thanks to the Author for the help and the project itself.