fnReloadAjax in separate js file
fnReloadAjax in separate js file
tacman1123
Posts: 211Questions: 47Answers: 1
First, thanks for a great tool, just amazing.
I'm setting up parent / child tables, e.g. click on a row in the invoice table and the item table automatically updates with items for that invoice. I've followed along with the examples and having it working with the fnReloadAjax plug-in, but since this situation shows up a lot, I want to put the plug-in into a separate js file and not keep pasting it before every .datatable() call.
So I created datatables.fnReloadAjax.js
[code]
$(document).ready(function() {
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
if ( typeof sNewSource != 'undefined' && sNewSource != null )
[REST OF PLUGIN CODE]
}
});
[/code]
and I load that js file right after jquery.datatables.js
[code]
[/code]
But this doesn't work. Cutting and pasting the plugin code, as is done in the examples, works.
So I'm guessing this has something to do with the plugin of a plugin. Any suggestions?
I understand that I can also use the redraw function, but obviously that doesn't change the Ajax url, which is what I need, since I need to pass the relevant foreign key id (e.g. invoice number). Is there an example of using redraw to change the ajax url?
I'm wondering why isn't this just included in the datatables core code? It seems like something that would be needed frequently.
Finally, is there another way to do with with the bDestroy param?
Would love to find the fastest way to do this, the related table changes really give it a powerful, dynamic feel.
Thanks, and again, datatables rocks, thanks for sharing it!
Tac
I'm setting up parent / child tables, e.g. click on a row in the invoice table and the item table automatically updates with items for that invoice. I've followed along with the examples and having it working with the fnReloadAjax plug-in, but since this situation shows up a lot, I want to put the plug-in into a separate js file and not keep pasting it before every .datatable() call.
So I created datatables.fnReloadAjax.js
[code]
$(document).ready(function() {
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
if ( typeof sNewSource != 'undefined' && sNewSource != null )
[REST OF PLUGIN CODE]
}
});
[/code]
and I load that js file right after jquery.datatables.js
[code]
[/code]
But this doesn't work. Cutting and pasting the plugin code, as is done in the examples, works.
So I'm guessing this has something to do with the plugin of a plugin. Any suggestions?
I understand that I can also use the redraw function, but obviously that doesn't change the Ajax url, which is what I need, since I need to pass the relevant foreign key id (e.g. invoice number). Is there an example of using redraw to change the ajax url?
I'm wondering why isn't this just included in the datatables core code? It seems like something that would be needed frequently.
Finally, is there another way to do with with the bDestroy param?
Would love to find the fastest way to do this, the related table changes really give it a powerful, dynamic feel.
Thanks, and again, datatables rocks, thanks for sharing it!
Tac
This discussion has been closed.
Replies
> Is there an example of using redraw to change the ajax url?
No - however you can simply do:
[code]
oTable.fnReloadAjax('new_source.php');
[/code]
which will reload from the new source.
> I'm wondering why isn't this just included in the datatables core code? It seems like something that would be needed frequently.
The same could be said for all of the plug-ins :-). Typically DataTables is used with DOM sourced client-side processing, Ajax sourced data less so (probably less than server-side processing as well, but I've not no numbers, so that's just a guess from the support requests!). It would be great to bundle up all the plug-ins, but the core size needs to be kept to a sensible size.
> Finally, is there another way to do with with the bDestroy param?
Yes you could destroy the table and initialise it with a new sAjaxSource address - that would work as well. Although fnReloadAjax should be faster, since the whole table doesn't need re-initalised.
> Thanks, and again, datatables rocks, thanks for sharing it!
Thanks :-)
Allan
The first one looks like what I pass into reload (with a _= variable, I'm guessing that's the session), then immediately after it finishes another one with the datatables params:
_ 1298919589535
bRegex false
bRegex_0 false
bRegex_1 false
bRegex_2 false
bRegex_3 false
bRegex_4 false
bRegex_5 false
bSearchable_0 true
bSearchable_1 true
bSearchable_2 true
bSearchable_3 true
bSearchable_4 true
bSearchable_5 true
bSortable_0 true
bSortable_1 true
bSortable_2 true
bSortable_3 true
bSortable_4 true
bSortable_5 true
class xora_location_class
iColumns 6
iDisplayLength 10
iDisplayStart 0
iSortCol_0 0
iSortingCols 1
s-user_id 1062493
sColumns
sEcho 1
sEcho 4
sSearch
sSearch_0
sSearch_1
sSearch_2
sSearch_3
sSearch_4
sSearch_5
sSortDir_0 asc
What do I need to do to avoid having the 2 calls?
Thx,
Tac