Refresh datatable after method call in MVC
Refresh datatable after method call in MVC
I have a datatable that loads ex. all my customers. After you click create new customer I want to refresh my datatable- get the new data from the database.
I see i can call fnReloadAjax() to reload the hash.
1. Where do I put this call. I would need to put datatable code in the view but I want it executed based on the controller.
2. What is the complete code to call this on my datatable?
This is what originally loads the datatable.
Thank you
oTable = $('#salespeople').dataTable({
"bProcessing": true,
"sPaginationType" : "full_numbers",
"bJQueryUI": true,
"bServerSide": true,
"sAjaxSource": '/Manage/GetSales',
"aoColumns": [
null,
null,
null,
null,
null,
{ "bSortable": false, "bSearchable": false,
"fnRender": function (oObj) {
return '';
}
}
]
});
I see i can call fnReloadAjax() to reload the hash.
1. Where do I put this call. I would need to put datatable code in the view but I want it executed based on the controller.
2. What is the complete code to call this on my datatable?
This is what originally loads the datatable.
Thank you
oTable = $('#salespeople').dataTable({
"bProcessing": true,
"sPaginationType" : "full_numbers",
"bJQueryUI": true,
"bServerSide": true,
"sAjaxSource": '/Manage/GetSales',
"aoColumns": [
null,
null,
null,
null,
null,
{ "bSortable": false, "bSearchable": false,
"fnRender": function (oObj) {
return '';
}
}
]
});
This discussion has been closed.
Replies
I am new to MVC and datatables.
I would love to put in my controller after you add new refresh oTable.fnReloadAjax() but I know this code cant go in a controller it needs to go in the view.
Can you tell me the exact code I need to add ot the view and what code in the controller I need to add to trigger that code?
THank you again
I'm not sure how your MVC is set up. The function call oTable.fnDraw() is a controller. The button you bind it to is in the view.
So somewhere in the view you have Add This User or something similar.
And somewhere in the controller you should have something similar to this (using .delegate, .live, .bind, .click as I'm using, or whatever)
[code]
$('.add_new').click(function() {
// Do all the stuff that happens after clicking "Add This User"
oTable.fnDraw(); // do the table redraw
});
[/code]