DataTables - push - from partial view
DataTables - push - from partial view

Can someone please assist me? From a partial view (modal) I am trying to call a function that will action the table.draw() method. The partial view successfully calls the find() function but the table.draw is not called.
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
alert("table.draw");
return true;
}
);
function find() {
alert("table redraw");
table.draw();
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Do you get errors in the browser's console?
My guess is
table
is undefined. The API docs explain how to get an API instance you can use in the find() function.Kevin
Kevin, my apologies for wasting your time. I should have posted all of the code. The table.draw does get called for each row initially when the grid is built. Just not on the click of the find button in the partial view.
https://jsfiddle.net/TimothyV/w8oja213/
The variable
table
is only available within the scope of$(document).ready()
. Your functions are outside this scope. Some options:$(document).ready()
var table
before$(document).ready()
and removevar
fromvar table = $('#example').DataTable({
.find()
function.Kevin
Kevin, thank you for your quick and accurate response. Like this?
No. Sorry I meant do one of the three options :-). I would just do this:
Added one line to your original code posting.
Kevin
Kevin, thank you so much! Everyone at https://datatables.net is amazing.
Have a wonderful weekend.