How to get the width of a column

How to get the width of a column

mleejrmleejr Posts: 7Questions: 0Answers: 0
edited October 2013 in General
I can see a datatable's column's width by inspecting the element in firebug. There it is under element.style { width: 64px; }

How do I get this value programatically in javascript?

$('#table_id thead th:eq('+index+')').css('width');

That shows undefined.

Replies

  • mleejrmleejr Posts: 7Questions: 0Answers: 0
    Hmm...I see lots of forum activity but no response. That's not a good sign. These seems like it'd be an easy 1 line solution but I can't find it anywhere. This has to be able to be done! Datatables is dynamically laying out the columns, I just want that value. Everything I try returns null or object not found or something.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Seems to work just fine for me: http://live.datatables.net/ugukuc/edit#javascript,html . Please link to a test case showing it not working, otherwise I'm just guessing! Also the forum rules note that you are unlikely to receive a reply unless a test case is provided.

    Allan
  • mleejrmleejr Posts: 7Questions: 0Answers: 0
    edited October 2013
    I found it. The problem is way one handles the dynamic management of showing/removing columns. I was not waiting for datatables to show/hide all it needs and THEN iterate through the list of remaining columns, grabbing the widths THEN...AFTER it was done with the show/hide logic. It was undefined because the columns were hidden.
This discussion has been closed.