Does DataTables support user-selectable column width resizing ?

Does DataTables support user-selectable column width resizing ?

BobZAnnapolisBobZAnnapolis Posts: 2Questions: 1Answers: 0

I essentially want to mimic how users can change an Excel's spreadsheet's individual column width by dragging-dropping the column border - this doable using Datatables ?

Our use case is that we are building a table dynamically from scratch inside a script that is going to be input variable length table column labels, along with all the data. For now, 99% of the data column cells are going to have numeric values with 1, maybe 2 columns having variable length strings.

To quickly get datatable functionality up & working, we're using the out-of-the box initialization settings.

This is all working fine, but once the table is displayed with actual data and we're looking at it, the question was asked "You know what would be real nice ? If we could let the users change the width of the columns like an Excel spreadsheet".

The columns that have numeric values take up a lot more space than they need to.
The table as a whole would look better if the columns that have the long-ish strings in them could be stretched to display all the text.

Since the table is going to be built dynamically, we're never going to know which specific columns/labels are going to have longer string values and which specific columns will have the shorter numeric values - and we don't want to put extra code in place that does any kind of pre-sizing of each column based upon content - we're happy with the default way it looks, and most times it will be enough - but on those off occasions it needs a little tweaking - we'd like to leave it up to the user to determine which columns they want wider.

Is user-selectable table column width sizing functionality available in Datatables ?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @BobZAnnapolis ,

    That's not possible, I'm afraid - the table columns can't be user dragged/resized. One thing you could try that may help is to add columns.adjust() into initComplete, that should resize the widths more sensibly.

    Cheers,

    Colin

  • BobZAnnapolisBobZAnnapolis Posts: 2Questions: 1Answers: 0

    Thanks for an answer.

This discussion has been closed.