How to refresh dataTables when using server-side processing (not AJAX source)?

How to refresh dataTables when using server-side processing (not AJAX source)?

newtodatatablesnewtodatatables Posts: 31Questions: 0Answers: 0
edited July 2011 in General
Hi, I am having trouble refreshing my dataTables after using one of the examples shown here http://www.codeproject.com/KB/java/JQuery-DataTables-Java.aspx (under Server side generated tables section) I want to add a button that allows the user to refresh the table that retrieves data from database. and I have tried using fnClearTable, fnReloadAjax and also fnDraw but none seems to work. I have no problems if I used a AJAX source. I am wondering if i made any mistakes..

Part of my Script

[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource ) {
if ( typeof sNewSource != 'undefined' )
oSettings.sAjaxSource = sNewSource;

this.fnClearTable( this );
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;

$.getJSON( oSettings.sAjaxSource, null, function(json) {
/* Got the data - add it to the table */
for ( var i=0 ; i

<%=c.getName()%>
<%=c.getAddress()%>
<%=c.getTown()%>

<%
}
%>




Refresh
[/code]

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited July 2011
    You've got '"bServerSide": false' and no Ajax source, so where are you expecting the new data to come from? Your "refresh" function at the moment will just redraw the current table view (i.e. look like it has done nothing).

    Allan
  • newtodatatablesnewtodatatables Posts: 31Questions: 0Answers: 0
    i have tried switching to bServerSide: true. Must I have an AJAX source?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    No - but you do need a data source. As I say, if you don't use Ajax, where are you expecting the new data to come from? You can use the API methods to add and remove data as you wish, but you need the new data.

    Allan
  • newtodatatablesnewtodatatables Posts: 31Questions: 0Answers: 0
    I see, I was expecting dataTables to call the arraylist ArrayList companyList = CompanyManager.getCompanyList(); as there will be new data inside getCompanyList(). This companyList is actually my data source that retrieves company objects from my database. I am trying to get it to refresh itself on button click.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    This DataTables library (it is not the DataTables built into .NET!) has no concept of server-side programming constructs such as ArrayLists in C#, Java or whatever you are using, and therefore it can't call it directly. It can get data from a json data source - it doesn't matter what the server-side language is, as long as it gives json back. Or from the DOM or plain javascript (see here: http://datatables.net/usage/ ).

    Allan
This discussion has been closed.