samedi 23 décembre 2017

Getting all selected rows with DataTables checkbox plugin with server side

I have this DataTable defenition:

  var availableFilesTable = $("#availableFiles").DataTable({
                'processing': true,
                'serverSide': true,              
                'ajax': '@Url.Action("GetAllBinariesExclude", "Program", new {programId = Model.Id})',
                'columns': [
                    {
                        data: 'Id',
                        'checkboxes': {
                            'selectRow': true
                        }
                    },
                    {
                        'data': 'BinaryName'
                    },
                    { 'data': 'Sha1Hash' }
                ],
                'select': {
                    'style': 'multi'
                },
                'order': [[1, 'asc']]
            });

I want to get all the selected rows and submit them to server, I have the following code for form submit event:

  $('form').submit(function(event) {
                event.preventDefault();

                var form = this;

                var existingFileIds = selectedFilesTable.column(0).checkboxes.selected();

                var fileIndex = 0;

                var newFiles = availableFilesTable.column(0).checkboxes.selected();

                $.each(newFiles,
                    function(index, fileId) {
                        $(form).append(
                            $('<input>')
                            .attr('type', 'hidden')
                            .attr('name', 'SelectedBinaryFilesIds[' + fileIndex + ']')
                            .val(fileId)
                        );
                        fileIndex++;
                    });

                if ($(form).valid()) {
                    form.submit();
                }
            });

The problem is that when I put a debugger and inspect the content of newFiles it only contains the content of active page of DataTable, Any hint on what am I doing wrong? I want to get all the selected rows in all pages with server side rendering but with the following code I only get the selected rows in the active page.

any help is much appreciated.




Aucun commentaire:

Enregistrer un commentaire