Quantcast
Viewing all articles
Browse latest Browse all 82150

Can't get server-side and select row both working at the same time

I made a server-side datatable for my MVC 4 C# project. Now I want to add a select row fuction, but I can't get it working. Here is my server-side datatable with a select row attept, wich doesn't work.

var oTable;

    $(document).ready(function () {
        /* Add a click handler to the rows - this could be used as a callback */
        $("#persons tbody tr").click(function (e) {
            if ($(this).hasClass('row_selected')) {
                $(this).removeClass('row_selected');
            }
            else {
                oTable.$('tr.row_selected').removeClass('row_selected');
                $(this).addClass('row_selected');
            }
        });

        oTable = $('#persons').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": document.URL,
            "sServerMethod": "POST",
            "aoColumns": [
                { "mData": "Naam" },
                { "mData": "Plaasts" },
                { "mData": "TaskId", "bSortable": false, "bVisible": false }]
        });
    });

    /* Get the rows which are currently selected */
    function fnGetSelected(oTableLocal) {
        return oTableLocal.$('tr.row_selected');
    }

But when I change this part.

oTable = $('#persons').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": document.URL,
            "sServerMethod": "POST",
            "aoColumns": [
                { "mData": "Naam" },
                { "mData": "Plaasts" },
                { "mData": "TaskId", "bSortable": false, "bVisible": false }]
        });

to this to this, then row selecting works. But there is now no server-side anymore.

oTable = $('#persons').dataTable();

I tried many things, but I can't seem server-side and the select row function work together. I really hope someone can help me with making in this code the server-side and row selecting work together.

Viewing all articles
Browse latest Browse all 82150

Trending Articles