Updates not working on second page

Updates not working on second page

rogersbillyrogersbilly Posts: 8Questions: 1Answers: 0
edited April 2014 in DataTables 1.9
I'm using Asp.net MVC to update the assigned user for a list of tasks. The update works fine on the first page no matter how many are displayed on the first page 10,50 or 100.

When we click 'Next' to go to the second page and click to update the tasks, the taskIds do not get posted back to the controller.

Can anyone see what I'm doing wrong in the code below?

[code]
/*global $, jQuery,document,fnCreateSelect*/
$(document).ready(function () {
"use strict";
$('.check:button').toggle(function () {
$('input:checkbox').attr('checked', 'checked');
$(this).val('uncheck all');
}, function () {
$('input:checkbox').removeAttr('checked');
$(this).val('check all');
});

/* Initialise the DataTable */
var oTable = $('#example').dataTable({
"aoColumns": [
{ "sWidth": "10%" },
{ "sWidth": "10%" },
{ "sWidth": "10%" },
{ "sWidth": "10%" },
{ "sWidth": "10%" },
{ "sWidth": "10%" },
{ "sWidth": "10%" },
{ "sWidth": "10%" }
],
"oLanguage": {
"sSearch": "Search all columns:"
},
"bAutoWidth": false
});

/* Add a select menu for each TH element in the table footer */
$("tr td.filter").each(function (i) {
if (i > 0) {
this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i));
$('select', this).change(function () {
oTable.fnFilter($(this).val(), i);
});
}
});
});

[/code]

Thanks for any help

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    See the top FAQ: http://datatables.net/faqs#events .

    Allan
  • rogersbillyrogersbilly Posts: 8Questions: 1Answers: 0
    I'm using the MVC model binding and not jQuery attached events to get the data. Do I need to switch to using jQuery to find all the checked checkboxes and get the ids instead of using the built in model binding?
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    No you just need to use the DataTables API to get all elements - see fnGetNodes .

    Your line `$("tr td.filter")` is only getting the nodes on the current page.

    Allan
  • rogersbillyrogersbilly Posts: 8Questions: 1Answers: 0
    edited April 2014
    So is this what I should use?

    var nNodes = oTable.fnGetNodes( );

    nNodes.each(function (i) {
    if (i > 0) {
    this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i));
    $('select', this).change(function () {
    oTable.fnFilter($(this).val(), i);
    });
    }
    });

    EDIT: that didn't work, not sure if that's what you meant though
  • rogersbillyrogersbilly Posts: 8Questions: 1Answers: 0
    edited May 2014

    I ended up taking a different approach. Instead of using Asp.net MVC model binding to pass the data back to the controller on the postback I wired up a button to call a jquery script. The jQuery script collects all the selected ids and passes them back to the controller using an ajax call.

    Now it works on all pages and when filtering/searching is used.

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Good to hear you got a solution in the end :-)

    Allan

This discussion has been closed.