Having trouble with bVisible in aoColumnDefs

Having trouble with bVisible in aoColumnDefs

airandfingersairandfingers Posts: 30Questions: 0Answers: 0
edited March 2012 in General
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

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Hi Aaron,

    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
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    Hm, I'm not sure why I didn't comment out the "Using aoColumns" part of that example.. It appears to work without that part (which was clearly overriding the previous dataTable declaration): http://live.datatables.net/apijum/2/edit

    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
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Hi 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
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    [quote]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?[/quote]
    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
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Hi 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
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    Hm, I just tried posting my error again (I tried on April 5 too), and got the same message as the first time - my post was "flagged for moderation". What's going on?
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    [code]

    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]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Each message in the forum is automatically scanned and checked if it is spam or not. If the system thinks it is, then it will place it in a queue for me to check manually if it is or isn't spam. Since I was away over the weekend there was a small back log including your message :-).

    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
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    I understand ^^

    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
This discussion has been closed.