Mixture of ServerSide Processing
Mixture of ServerSide Processing
Hi Allan,
Sorry if some one has already asked this question earlier, but I was not able to find the Answer in Prev Topics
In Server Side Processing, you said "Basically all of the paging, filtering, sorting etc that DataTables does can be handed off to a server (or any other data source - Google Gears or Adobe Air for example!) and DataTables is just an events and display module."
DataTables is just an events and display module... !!
I was wondering if I can use Mixture of Both. I dont want the sorting/Pagination/Filtering to be carried on at Server-Side , but still get the Server Side Data by Using sAjaxSource....
Thanks in Advance
Sobers
Sorry if some one has already asked this question earlier, but I was not able to find the Answer in Prev Topics
In Server Side Processing, you said "Basically all of the paging, filtering, sorting etc that DataTables does can be handed off to a server (or any other data source - Google Gears or Adobe Air for example!) and DataTables is just an events and display module."
DataTables is just an events and display module... !!
I was wondering if I can use Mixture of Both. I dont want the sorting/Pagination/Filtering to be carried on at Server-Side , but still get the Server Side Data by Using sAjaxSource....
Thanks in Advance
Sobers
This discussion has been closed.
Replies
I'm not quite sure I understand what you are looking for. You want to load data from the server, but then have sorting etc done on the client-side? This is achieved through the Ajax source, data source option: http://datatables.net/examples/data_sources/ajax.html
Regards,
Allan
"bServerSide": true...
With this we cannot have Client Side Sorting, "bSortable": true... All we can do is, sort on server side. Same is true for Filter... What I was looking, if we can have these features with "bServerSide": true w/o taking care of them on server-side...
If you remove the bServerSide:true, then it will still load the data from the server source (as a JSON object), but do all the processing client-side:
Ajax Source ( http://datatables.net/examples/data_sources/ajax.html ):
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": '../examples_support/json_source.txt'
} );
} );
[/code]
Server-side processing ( http://datatables.net/examples/data_sources/server_side.html ):
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php"
} );
} );
[/code]
Regards,
Allan
Thanks for the Solution, I got it working
I do have another question,
Can we use fnDataUpdate with getJSON to update each row, instead of fnReloadAjax/.. do you think it will give perfromance gain when I am doing reload every 5 secs ?
fnReloadAjax() is just going a $.getJSON() call - so I suspect that there wouldn't be any performance benefit in this case - indeed you might find that the method used in fnReloadAjax() is about as fast as a full table update can be :-)
Regards,
Allan
My Problem is I keep on refreshing my table every five seconds and the reload is not smooth using fnReloadAjax()
I see the table redrawn, So was thinking of any other alternative.
PS I am not using server-side proc, else fnDraw was a perfect solution
Sobers
When your say you can see the table being redrawn, do you mean you can see it being emptied and then filled again? This should happen with fnReloadAjax() since the clear table function won't redraw the table, nor will anything else until the fnDraw function is called.
However, perhaps you meant that it jumps back to page 1, and you can see the data shifting around? In which case, yes, fnUpdate() probably would be the best way to go, but you need to be careful if you want to sort/filter the new data or not. It also won't be quite as fast as fnReloadAjax(), but if that is noticeable or not depends on your data set size.
Regards,
Allan
Yes, I see the table Emptied and redrawn again, and It doesnt look like a smooth update...
Earlier I use to do ServerSide Proc and use fnDraw, which worked perfect, but since i wanted to handle the Filters and Pagination on Client Side, I used the Non-ServerSide...which made me use fnReloadAjax....
Also one more question, Maybe its answered by you earlier on prev topics, but was not able to find one...!!
Why does fnReloadAjax make 2 calls to server, one with Params and one without... ?
My DataSet is not as huge, but I do have 2 Dynamic Columns which are drawn on every call back, in fnRowCallBack
This is the last thing I am stuck at.. :-(
Thanks for all your help so far.
Sobers
1. Try this small alteration for the fnReloadAjax() function:
[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback )
{
if ( typeof sNewSource != 'undefined' )
{
oSettings.sAjaxSource = sNewSource;
}
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
$.getJSON( oSettings.sAjaxSource, null, function(json) {
that.oApi._fnClearTable( oSettings );
/* Got the data - add it to the table */
for ( var i=0 ; i
Helped a Loot... Its such a smooth refresh now...
Also I had to Explicitly say "bServerSide": false, to stop the second call...
The Table looks So great now...
Got a loot of functionalities in there, with dynamic Columns, Row Details, Styles, Reload and Many ...
I owe you a big time man
Thanks VeryMuch
Sobers
I have one more question ..
I am using the fnReloadAjax, which gets the json from the server. I am adding some more params to the json to be displayed on the screen.
If I have an alert, inside fnReloadAjax, it shows only one time. So I am not able to use the params in Json to display on screen everytime new json is fetched from server inside the fnReloadAjax function.
I tried to use callback function, but I am not able to access these params/variables inside the function....
Any way arround this problem ?
Thanks
How about a small modification to the reload Ajax function to pass the JSOn to the callback function then?
fnCallback( oSettings );
to
fnCallback( oSettings, json );
would give you the JSON in the callback function as the second parameter.
Regards,
Allan
//fnReloadAjax Call
oTable.fnReloadAjax(addParams());
//inside the CallBack function of getJSON of fnReloadAjax
fnCallback( oSettings, json );
// Call Back function
function addParams(oSettings, json){
alert(json);
alert(oSettings);
}
Both of them come tobe "undefined"
I dont know if I am doing something wrong
Sobers
Try passing the addParams function, rather than calling it:
//fnReloadAjax Call
oTable.fnReloadAjax(addParams);
:-)
Regards,
Allan
the
alert( typeof fnCallback == 'function' )
Shows False ..and never executes the addParams() function
Sorry I am not a JavaScript Guru, So maybe I am doing something wrong
Sobers
Do you define addParams() before you pass it into the function? Perhaps if you have a link you could provide I'd be able to look at the whole source.
Regards,
Allan
I have another Issue.
I am using the above modified version of fnReloadAjax, which works perfect. I refresh my page per 5 sec's and it works nice....
In Each row I have a Row_Details action, which user might choose to see more details.
To maintain the state of which row was open upon refresh/reload, I am using an array and it works perfect. I add this open row by using "fnRowCallback".
The problem is, if any row is open and the page refreshes, the screen looks jumping, since I see that it adds this details-row after it has drawn the table.So if we keep the row-open/details-open every 5 secs when the screen refreshes, the screen looks weird.
Hope my explanation was not confusing... Please let me know
I am using the below in fnRowCallback.
cTable.fnOpen( nRow, data, 'details' );
The If Loop checks if the current row was the one left open before refresh
Thanks
Not sure if this is a Bug, given my poor knowledge with JavaScript
in the function
function _fnDraw( oSettings ){ }
you are initializing the variable
var iOpenRows = oSettings.aoOpenRows.length;
Later when we have a fnRowCallBack >>>
if ( typeof oSettings.fnRowCallback == "function" )
{
nRow = oSettings.fnRowCallback( nRow,
oSettings.aoData[ oSettings.aiDisplay[j] ]._aData, iRowCount, j );
if ( !nRow && !bRowError )
{
alert( "Error: A node was not returned by fnRowCallback" );
bRowError = true;
}
}
and lets say I am adding a Row to the Current Row
The Code following
if ( iOpenRows !== 0 ){}
Wont get executed, since the iOpenRows is Initialized earlier and does not reflect the latest Value
I also found the size of aoOpenRows goes on increasing after each CallBack, Maybe I am wrong, but will double check on that
Please help
Sobers
If you are using fnRowCallback to "open" a row, isn't the node added by the fnOpen function? Why would it also need to be added after the fnRowCallback - I might be missing something here, since I haven't set up a working example yet (sorry, trying run through the 40 odd posts...!) - if you have a link to an example, that would be most useful.
Regards,
Allan