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
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.
[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.
This discussion has been closed.
Replies
Use:
[code]
$("#persons tbody").on( 'click', 'tr', function (e) {
[/code]
Allan
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