mercredi 23 novembre 2016

Issue with jQuery Datatable multi item selection

I use this extension for my data table. What I want is to save selected rows across all pages, and this is what the plugin was created for. Example works fine, but if I change source of data from json file to asp mvc action method, plugins behavior becomes confused. If you select at least one row and try to go to another page or try to sort table by some column, all checkboxes on the page will be selected. If non of checkboxes were selected before you try to operate with data table, no-one checkbox will be selected. Did anyone get this problem?

My sample project is:

html

<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th></th>
            <th>num</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th></th>
            <th>num</th>
        </tr>
    </tfoot>
</table>

js:

 $(document)
    .ready(function() {
        $('#example')
            .DataTable({
                ajax: '@Url.Action("Data")',
                columnDefs: [
                    {
                        targets: 0,
                        checkboxes: {
                            selectRow: true
                        }
                    }
                ]
            });
    });

and finally data source

public JsonResult Data()
{
    return new JsonResult(new
    {
        data = new List<string[]>
        {
            new[] {"", "198"},
            new[] {"", "2"},
            new[] {"", "3"},
            new[] {"", "4"},
            new[] {"", "5"},
            new[] {"", "11"},
            new[] {"", "12"},
            new[] {"", "13"},
            new[] {"", "14"},
            new[] {"", "15"},
            new[] {"", "10"},
            new[] {"", "20"},
            new[] {"", "30"},
            new[] {"", "40"},
            new[] {"", "50"}
        }
    });
}

P.S. I use ASP .NET Core, but it does not matter.




Aucun commentaire:

Enregistrer un commentaire