0

I need help in regards to updating a table rendered by jQuery data-tables plugin.

I have a view called Index.aspx in which I have a DIV, where the traditional table data is rendered. Something like:

<div id="students">
    <table ...>
         <thead>
           ...
         </thead>
         <tbody>
           ... (all the rows are statically rendered to DOM)
         </tbody>
    </table>

</div>

Then, I initialize the datatable as:

$(document).ready(function(){
    $("#students").dataTable();
});

The approach I have designed to use this along with CRUD operations is as follows:

All INSERT, UPDATE and REMOVE scenarios call an Action which returns a PartialView that updates the DIV.

However, even though I see the data is updated properly, I lose dataTable's functionalities like Paging, Sorting, etc. It doesn't even reflect the correct number of records in the datatable.

I understand this is happening because dataTable caches the data in its internal structure, so when I update the portion of the page using Ajax, dataTable is unaware of the data changes.

Has anyone come across this situation? What is a NICE and CLEAN approach to fix this problem?

Cheers,

Mosh

2 Answers 2

1

have you tried calling fnDraw after ajax?

Sign up to request clarification or add additional context in comments.

Comments

1

Try something like this in your code where you need to refresh your table:

oCache.iCacheLower = -1;
oTable.fnDraw();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.