Limiting column widths

Limiting column widths

StanAccyStanAccy Posts: 31Questions: 5Answers: 0

We are generating a table with Datatables 1.10 on the server side and sending the whole set of JS + data back to the client.
Its working very well, with one exception - column widths.

Right now, it looks like Datatables has run some algorithm to set column widths and its set the width property on each <th>.

Is there a way to hook in to the width generation and provide a max-width limit along with appropriate word-break / word-wrap options?

Answers

  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    Could we add an additional value to the aoColumns like sWidthMax, or is it possible to provide our own implementation of the _fnCalculateColumnWidths() method?

    We'd basically just copy that method and put a cap on max col width, allocating any excess space to the widest column, and also set word-wrap/word-break on each col.

  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    This seems to work - comments please:

    Index: datatable/resources/js/jquery.dataTables-1.10.4.js
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- datatable/resources/js/jquery.dataTables-1.10.4.js  (revision ee0c0ecdfa1ce93794733baa66391906317c374a)
    +++ datatable/resources/js/jquery.dataTables-1.10.4.js  (revision )
    @@ -4196,13 +4196,16 @@
                    tmpTable.width( _fnStringToCss( total ) );
                    table.style.width = _fnStringToCss( total );
                }
    -   
    +
                // Get the width of each column in the constructed table
                for ( i=0 ; i<visibleColumns.length ; i++ ) {
                    column = columns[ visibleColumns[i] ];
                    width = $(headerCells[i]).width();
    -   
    +
                    if ( width ) {
    +                   if( column.sMaxWidth && width > column.sMaxWidth ) {
    +                       width = column.sMaxWidth;
    +                   }
                        column.sWidth = _fnStringToCss( width );
                    }
                }
    @@ -9463,7 +9466,8 @@
             *  @default null
             */
            "sWidth": null,
    +       "sMaxWidth": null,
    -   
    +
            /**
             * Width of the column when it was first "encountered"
             *  @type string
    
  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    Now that Ive used this, I realized that I dont want to set this property on a per column basis, but on the entire table, as a single setting. Could this be done at a table wide level?

This discussion has been closed.