Problems using aoColumns dynamically with defined column array

Problems using aoColumns dynamically with defined column array

ole_ole_ Posts: 2Questions: 0Answers: 0
edited February 2013 in Plug-ins
Hello everyone!

The idea is that I want to use autodetectable sorting on my datatables which work good, but in cases where I have textboxes, checkbox or other, I use sSortDataType, and it seems to work also! But! I'm having some problems with aoColumns when using an array, dynamically defined on every subsite. When I go into a subsite I start with defining the columns attached like this:

[code]
ths.each( function( index ) {
th = $(this);
if( th.attr('sorting') ) {
var column = '{ "sSortDataType": "' + th.attr('sorting') + '" }';
} else {
var column = "null";
}
aoColumn.push(column);
}
[/code]
dom-text is then defined in the header of where I have textboxes columns. All "null" are handled with auto-type detection.

A console.log of "aoColumn" gives for example:
{ "sSortDataType": "dom-text" }, null, null, null, { "sSortDataType": "dom-text" }, null

I want to do it like this, by insert the array to aoColumns, but it doesn't work!:

[code]
var options = {
"aLengthMenu": [[10, 50, 100, -1], [10, 50, 100, "All"]],
"aoColumns": aoColumn,
....
};
[/code]

but if I hardcode my array from one subsite into the aoColumns like this it works!!!;

[code]
var options = {
"aLengthMenu": [[10, 50, 100, -1], [10, 50, 100, "All"]],
"aoColumns": [
{ "sSortDataType": "dom-text" },
null,
null,
null,
{ "sSortDataType": "dom-text" },
null
],
....
};
[/code]

It works very nicely even if I write new text into textbox, they are sorted good. But only in the hardcoded example. How can I get my dynamic array to work? Any idea? If you need more code or explaination, please tell me.

Thanks,
Ole

Replies

  • ole_ole_ Posts: 2Questions: 0Answers: 0
    Finally identified the problem.. The answer was here;
    http://datatables.net/forums/discussion/6260/dynamic-column-names/p1

    var column = '{ "sSortDataType": "' + th.attr('sorting') + '" }';

    should instead be

    var column = { "sSortDataType": th.attr('sorting') };
This discussion has been closed.