Having trouble with bVisible in aoColumnDefs
Having trouble with bVisible in aoColumnDefs
airandfingers
Posts: 30Questions: 0Answers: 0
I'm trying to use bVisible to hide one of my tables' columns, but I'm having trouble initializing the table with those settings.
My example is complicated and wouldn't make sense without hundreds of lines of code that support it, but I think I've demonstrated a problem with bVisible here:
http://live.datatables.net/apijum/edit#javascript,html,live (note that only one column is hidden)
Again, the problem I'm having is different, though my code is slightly similar to this code in that I have multiple definitions in my aoColumnDefs setting. The actual error I get during initialization is the not-so-useful "Cannot read property 'sWidth' of undefined" when the code apparently tries to draw a table that doesn't exist.
Note that I'm using DataTables version 1.8.2. I'm more than willing to update to 1.9, but right now I'd rather now unless this issue is likely to be fixed by updating.
Thanks,
Aaron
My example is complicated and wouldn't make sense without hundreds of lines of code that support it, but I think I've demonstrated a problem with bVisible here:
http://live.datatables.net/apijum/edit#javascript,html,live (note that only one column is hidden)
Again, the problem I'm having is different, though my code is slightly similar to this code in that I have multiple definitions in my aoColumnDefs setting. The actual error I get during initialization is the not-so-useful "Cannot read property 'sWidth' of undefined" when the code apparently tries to draw a table that doesn't exist.
Note that I'm using DataTables version 1.8.2. I'm more than willing to update to 1.9, but right now I'd rather now unless this issue is likely to be fixed by updating.
Thanks,
Aaron
This discussion has been closed.
Replies
Thanks for the live example - although when I run it I get an error about initialising the DataTable twice (which is correct, you can't do that). Either individual example seems to work okay - I don't get any errors about sWidth.
Might you be defining more columns in aoColumns / aoColumnDefs than you actually have int he table? Can you run your table through the debugger please: http://debug.datatables.net ?
Allan
Running the debugger wasn't easy (I had to use proxies to get around some intra/Internet issues), but here's the debug data for only the table in question: http://debug.datatables.net/onifit
To be honest, I'd love to send you all my DataTables-related code so that you could help me debug and improve it (I see your support prices have gone up ^^), but my employer has valid concerns about sharing any of our intellectual property without a non-disclosure agreement set up.
Would you be interested in supporting us in ways that would involve looking at our source code (or even accessing our intranet-only site)? If so, I believe I could get an NDA over to you for your approval sometime soon; if not, we can proceed as we have done so far, using jsbin and limited debugger output.
Thanks,
Aaron
Thanks for the debug trace - I'm curious why you would have had to use a proxy to get to the debugger - can you not access the public internet without a proxy? The whole point of the debugger was to try and make debugging internal applications easier!
The one thing from your trace that looks a little funny to me is that the first column as a title of "undefined". You've got 8 columns in the table - can you confirm that you have 8 columns in the HTML before you initialise the DataTable? You need to have 8 and not 7 since DataTables will hide the first column for you.
Regarding the NDA - generally speaking I won't sign NDAs because of the wide ranging nature of supporting DataTables. For example, if you were (let's say) working on educational software and I signed your NDA that had a non-compete clause in it, then I helped someone else working on educational software, I could potentially be breaching the NDA! If the NDA says basically that data and code wouldn't be shared, then I'd be willing to look at it :-). I hope you understand.
Regards,
Allan
I need a proxy to access my site, and the proxy Extension I have installed isn't flexible enough to switch between using the proxy and not using it as needed. It's no big deal - I just had to manually switch my proxy after loading the page and before running your bookmarklet - but something I could run without Internet access would be a bit easier for me to use.
[quote]can you confirm that you have 8 columns in the HTML before you initialise the DataTable?[/quote]
I'm creating the HTML table dynamically using jQuery, and doing so with a function that reads from a list of table columns I've defined for each of my tables. For the id column, I hadn't given it a "name" to display as (since it's supposed to be invisible anyway), so my function was titling the column "undefined". I just gave that column the name "ID", and here's the HTML of the table if I don't call dataTable() on it:
[code]
ID
Alert Status
Alert Type
Severity Level
Alert Parameters
Source GUID
Source Component
Time Received
3
ACTIVE
SA_CONNECTION_CREATED
NOTIFICATION
{"initiator": "63636330370000000000000000000000", "responder": "63636330350000000000000000000000", "child_type": "CST_ESP"}
63636330350000000000000000000000
SA
2012-04-04 10:29:22
4
ACTIVE
SA_CONNECTION_CREATED
NOTIFICATION
{"initiator": "63636330390000000000000000000000", "responder": "63636330350000000000000000000000", "child_type": "CST_ESP"}
63636330350000000000000000000000
SA
2012-04-04 10:29:22
[/code]
8 columns, and I think I followed the rules DataTables asks me to follow (one tr full of th's in thead, all rows in tbody..)
[quote]If the NDA says basically that data and code wouldn't be shared, then I'd be willing to look at it :-).[/quote]
That's what I'd intend for it to say ^^. I'll talk with my supervisors soon; I think their main concern is with someone stealing our code.
Thanks,
Aaron
Your HTML looks absolutely perfect! I'm surprised that DataTables is objecting to that in some way. Could you tell me what line number the JS error is occurring on with the unminified version of DataTables? That will give me a starting point in the code to work back, combined with your debug trace, I'll hopefully be able to see what is happening!
Thanks,
Allan
Uncaught TypeError: Cannot read property 'sWidth' of undefined
_fnScrollDraw jquery.dataTables.js:4025
_fnDraw jquery.dataTables.js:3392
_fnFilterComplete jquery.dataTables.js:4357
_fnSort jquery.dataTables.js:4744
_fnReDraw jquery.dataTables.js:3422
$.fn.dataTable.fnDraw jquery.dataTables.js:1523
Scroller.fnMeasure Scroller.js:334
Scroller._fnConstruct Scroller.js:376
Scroller Scroller.js:186
$.fn.dataTableExt.aoFeatures.push.fn InitScroller.js:791
_fnAddOptionsHtml jquery.dataTables.js:3760
_fnInitialise jquery.dataTables.js:2365
$.fn.dataTable jquery.dataTables.js:7436
e.extend.each jquery.js:2
e.fn.e.each jquery.js:2
$.fn.dataTable jquery.dataTables.js:6923
TABLES.initTable tables.js:54
(anonymous function) alerts.js:139
f.Callbacks.n jquery.js:2
f.Callbacks.o.fireWith jquery.js:2
w jquery.js:4
f.support.ajax.f.ajaxTransport.send.d jquery.js:4
[/code]
Thanks for posting the trace - can you confirm which version of Scroller you are using please? If you aren't already, could you upgrade to the 1.0.2 dev version from the download page: http://datatables.net/download .
This is the line in DataTables 1.8.2 that is tripping up:
[code]
nThs[i].style.width = o.aoColumns[iVis].sWidth;
[/code]
what would be interesting to know is what 'iVis' is at this point when the error occurs. Could you possibly add in a trace that will check that?
You could also try putting the 'S' option in sDom at the end of the string, rather than immediately after the 't'. I'm not sure if that will address the problem, but it wouldn't do any harm and would allow the rest of the features to initialise first.
Thanks,
Allan
Thanks for the multiple suggestions! I upgraded to Scroller 1.0.2 dev, and the problem went away! I now have an invisible ID column, and that's all I wanted.
Thanks again!
-Aaron