vendredi 24 février 2017

jquery Datatables row grouping with checkbox

I have a datatable in which I would like to apply row grouping to it. Also included is a checkbox plugin. I've tried the code listed on the datatables website, but I had no luck. The api doesn't add the row for the grouping for the "City" column. The code I used for the grouping is shown below:

$(document).ready(function (){
          $('#example').DataTable({
            columnDefs: [{
                targets: 0,
                'checkboxes': {
                    'selectRow': true
                }
            },
            { "visible": false, "targets": 1 }],
            select: {
                style: 'multi'
            },
            order: [[1, 'asc']],
            iDisplayLength: 10,
            drawCallBack: function () {
                var api = this.api();
                var rows = api.rows({ page: 'current' }).nodes();
                var last = null;

                api.column(1, { page: 'current' }).data().each(function (group, i) {
                    if (last !== group) {
                        $(rows).eq(i).before(
                            '<tr class="group"><td colspan="6">' + group + '</td></tr>'
                        );

                        last = group;
                    }
                });
            }
        });
});

I have the code in my jfiddle here. Could the checkbox be interfering with the grouping? Please let me know where I am going wrong.

Note: The checkbox is based on the plugin by gyrocode The datatables is version 1.10.12




Aucun commentaire:

Enregistrer un commentaire