====== DataTables Set Column Width ====== There are two ways to do so. ===== Method 1: Set it directly in HTML Tag ===== Just set it directly in the HTML tag with the word ''width''. The following example set the width in the table header fields.
Header 1 Header 2 Header 3
r1 c1 r1 c2 r1 c3
r2 c1 r2 c2 r2 c3
r3 c1 r3 c2 r3 c3
===== Method 2: Use columnDefs===== $("#my-table").dataTable({ columnDefs: [ { "targets": [0], "visible": true, "width": "15%" }, { "targets": [1], "visible": true, "width": "15%" }, { "targets": [2], "visible": true, "width": "70%" } ] }); ===== Handling Very Long Contents in Table Cell ===== By default, the HTML table style ''table-layout'' is auto. This mean the cell will auto abject the width of the cell if needed, such as the content is one single very loooooooooooooooooooooooooooooooooooong word. {{ :datatables:datatablewidth1.png?direct&400 |}} To enforce the exact width, you should change the ''table-layout'' to ''fixed''. . . .
{{ :datatables:datatablewidth2.png?direct&400 |}} To make the text fit the cell without over shooting, we might need to break the word like: r1 c1 very Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong r1 c2 r1 c3 {{ :datatables:datatablewidth3.png?direct&400 |}}