Checkboxes column problem, automatically checked all checkboxes

Checkboxes column problem, automatically checked all checkboxes

idimitrovidimitrov Posts: 2Questions: 0Answers: 0

Hello to everyone, I have a problem with a checkbox column in my table. I am using Gyrocode plugin and Select extension. After checking one checkbox and changing the page or refresh the page, all checkboxes on each row is checked automatically. Here is my code.

$(function () {
            var table = $('#employeesListTable').DataTable({
                ajax: {
                    "url": "@Url.Action("EmployeeListData", "Employee")",
                    "type": "POST",
                    "datatype": "json",
                     data: function (d) {
                        d.onlyActive = $("#onlyActive").length == 0 || $("#onlyActive").is(':checked');
                    }
                },
                fnInitComplete: function (settings, json) {
                    initDataTablesSearch(settings);
                    $('div.custom-filter').html(TemplateToHtml('#templateOnlyActive'));
                },
                select: {
                    style: 'multi',
                    selector: 'td:first-child'
                },
                columns: [
                    {                           
                        orderable: false,
                        targets: 0,
                        'checkboxes': {
                            'selectRow': true,
                        },
                        defaultContent: '',
                        data: 'rowId'
                    },
                    {
                        name: 'td',
                        data: 'td',
                        title: 'ТД',
                        sortable: true,
                        searchable: true
                    },
                    {
                        name: 'name',
                        data: 'name',
                        title: 'Име',
                        sortable: true,
                        searchable: true
                    },
                    {
                        name: 'branch',
                        data: 'branch',
                        title: 'Клон',
                        sortable: true,
                        searchable: true
                    },
                    {
                        name: 'department',
                        data: 'department',
                        title: 'Отдел',
                        sortable: true,
                        searchable: true
                    },
                    // button columns
                    {
                        name: 'dossier',
                        data: "id",
                        sortable: false,
                        searchable: false,
                        className: "text-center noExport",                       
                        "render": function (data, type, row, meta) {
                            return TemplateToHtml('#templateDossier', row.id);
                        }
                    },
                    {
                        title: ' ',
                        sortable: false,
                        searchable: false,
                        render: function render(data, type, row, meta) {
                            return TemplateToHtml('#templateCv', row);
                        }
                    },
                    {
                        title: ' ',
                        sortable: false,
                        searchable: false,
                        render: function render(data, type, row, meta) {
                            return TemplateToHtml('#templateEditEmployeePerson', row);
                        }
                    }                   
                ],
                order: [[1, 'asc']],
                language: {
                    select: {
                        rows: {
                            _: "Избрани са %d реда",
                            0: '',
                            1: "Избран е 1 ред"
                        }
                    }
                },
                rowId: function (row) {
                    return 'id_' + row.id;
                },
                'stateSave': true
            });

Replies

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    You have 'stateSave': true which I believe the Gyrocode checkboxes plugin checks in order to save the checkbox state. If you don't want the checkboxes save you can check with Gyrocode Chockboxes docs or maybe the developer to see how to turn it off. Or you might be able to use the stateLoadParams to remove the checkbox state.

    Kevin

  • idimitrovidimitrov Posts: 2Questions: 0Answers: 0

    Thank you for the fast response kthorngren. The problem is that when I click on one checkbox and refresh the page - all checkboxes are checked. And opposite, if i deselect one checkbox and refresh the page - all checkboxes are unchecked.

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    You are using a third party plugin to for the checkboxes. You can work with that developer to find the issue or post a link to your page or a test case replicating the issue here for our help. Without actually seeing the problem it will be hard to help troubleshoot.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.