$('#myDataTable').dataTable() is throwing exception

$('#myDataTable').dataTable() is throwing exception

saleemy2kssaleemy2ks Posts: 1Questions: 0Answers: 0

Hello, I am using DataTables 1.10.7 version. I am creating the datatable using the script as given below:
<script type=\"application/json\" data-for=\"myDataTable\">{\"x\":{\"data\":[["+jsonIDList+"],["+jsonLocations+"],["+jsonScore+"]],\"container\":\"

\\n \\n \\n \\n \\n \\n \\n \\n
IDLocationScore

\",\"options\":{\"pageLength\":15,\"autoWidth\":true,\"columnDefs\":[{\"className\":\"dt-right\",\"targets\":2}],\"order\":[],\"orderClasses\":false,\"orderCellsTop\":true,\"lengthMenu\":[10,15,25,50,100]},\"callback\":null,\"filter\":\"top\",\"filterHTML\":\"<tr>\n <td data-type=\\"character\\" sType=\\"html\\" style=\\"vertical-align: top;\\">\n

\\n \\n \\n

\n </td>\n <td data-type=\\"character\\" style=\\"vertical-align: top;\\">\n

\\n \\n \\n

\n </td>\n <td data-type=\\"number\\" style=\\"vertical-align: top;\\">\n

\\n \\n \\n

\n

\\n
\\n \\n \\n

\n </td>\n</tr>\"},\"evals\":[]}<\/script>

This is working fine with filtering and searching. I have a requirement to add a new Reset button when clicked i need to reset the search and filter criteria to default.
I am using the below code when reset button [<button type="button" onclick="resetmyDataTable();" class="btn btn-default">Reset map</button>] is clicked

function resetmyDataTable()
{
var table = $('#myDataTable').dataTable();
// Perform a filter
table.fnFilter('Win');
table.fnFilter('Trident', 0);
// Remove all filtering
table.fnFilterClear();
}

But $('#myDataTable').dataTable() is throwing exception : Unable to get property 'nTable' of undefined or null reference
Below is the call stack during the exception:
7-w - exception line: h(a.nTable).trigger(b,e)
6-I
5-Anonymous function
4-each
3-each
2-m()
1-resetmyDataTable()

the w function:
function w(a,b,c,e){var d=[];b&&(d=h.map(a[b].slice().reverse(),function(b){return b.fn.apply(a.oInstance,e)}));null!==c&&(b=h.Event(c+".dt"),h(a.nTable).trigger(b,e),d.push(b.result));return d}

Appreciate any help on this.

Replies

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    I've also deleted your duplicate discussion on this topic.

This discussion has been closed.