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

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

ShonofShonof Posts: 2Questions: 0Answers: 0
edited February 2013 in General
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.

[code]
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');
}
[/code]

But when I change this part.

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

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

[code]
oTable = $('#persons').dataTable();
[/code]

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.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    That's adding a static event handler. See: http://datatables.net/faqs#events

    Use:

    [code]
    $("#persons tbody").on( 'click', 'tr', function (e) {
    [/code]

    Allan
  • ShonofShonof Posts: 2Questions: 0Answers: 0
    edited February 2013
    I found a solution! This works and I don't know why actually... But I still want to thank you for your help, because you changed my way of thinking/searching for the solution!

    This works
    [code]
    $("#persons tbody tr").live('click', function () {
    [/code]

    Changing this
    [code]
    $("#persons tbody tr").click(function (e) {
    [/code]
    to this
    [code]
    $("#persons tbody").on( 'click', 'tr', function (e) {
    [/code]

    Let only server-side work, but not the row selecting
This discussion has been closed.