Class Selector

Class Selector

craincrain Posts: 1Questions: 0Answers: 0
edited November 2011 in General
Hi there, we are using a template called readymadeadmin from themeforest and want to implement i18n for the datatable descriptions.
It looks like that the template is rendering the datatable via class selector ""
Sadly we are not able to access this selector to add the i18n features with:
[code]"oLanguage": {
"oPaginate": {
"sFirst": "First page"
}
}[/code]

If I assign an id to this table and try access it via:
[code]
$('#datatable').dataTable({
})
[/code]
I get an error called:
[quote]
DataTables warning (table id = 'datatable'): Cannot reinitialise DataTable.
[/quote]

Can somebody help me on this?
Thanks a lot!

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    You can definitely use an ID instead of a class; that's what we're doing with one of our applications. I would also assign the dataTable object to a variable so that you'll have flexibility digging into it later:

    [code]
    var oTable = $('#datatable').dataTable({ ...your initialization parameters ...});
    [/code]

    What's throwing me off in terms of missing information is why you're getting a "reinitialise" error. Sounds like you're calling dataTable on it twice? In the even that you want to re-draw, there are a few ways to do this, including the one I use (since I use server-side processing), fnDraw.

    [code]
    oTable.fnDraw();
    [/code]

    If you're literally trying to call dataTable on it with empty curly braces (passing an empty list of parameters) that won't work. You can re-initialize the table by calling the function as void. I don't think you'd want to do this if you're declaring the table as a variable, though. Assuming you've only created it (as per your example) with a raw jQuery object, this is how you would re-init:

    [code]
    $('#datatable').dataTable();
    [/code]
This discussion has been closed.