Problem with columDefs

Problem with columDefs

JochenKJochenK Posts: 55Questions: 10Answers: 0

Link to test case:
https://live.datatables.net/sasumidi/1/edit

Description of problem:
I want to set the 2nd column ("Thema") in my datatable to 20%.
I use columnDefs for this, but it doesn't seem to work. What can I do ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    20% width? You might want to do that, and DataTables is applying that, but the content doesn't allow it to be 20% width. You have:

    th, td { white-space: nowrap; }
    

    and since it is a long string, it is correctly showing as a very wide cell.

    You could allow the text to wrap, or you could could consider doing something like the ellipsis renderer.

    Allan

  • JochenKJochenK Posts: 55Questions: 10Answers: 0

    20% was an example. The 2nd column can contain very long text. Therefore, the column should have a maximum width and the text should wrap into several lines.

    The text can be limited with "the ellispsis renderer" and the column width can also be set automatically. However, then I can only set a filter in the search field for the text displayed, in the truncated text is not filtered.

    I solved the problem with a div in the td.
    the td : { white-space: normal !important; }
    the div: { width: 300px; } - px is selectable

    https://live.datatables.net/bifomimo/1/edit

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited December 4 Answer ✓

    However, then I can only set a filter in the search field for the text displayed, in the truncated text is not filtered.

    That is not true. As documented at the link Allan posted use Orthogonal data to render the ellipsis for only the display operation. Here is your test case with an ellipsis renderer. You can search for hidden text, like M13, and see the row is still displayed.
    https://live.datatables.net/sasumidi/3/edit

    Kevin

  • JochenKJochenK Posts: 55Questions: 10Answers: 0

    Yes you are right.
    I didn't set datatable.reender initially. That was my mistake.
    Now it works like it should,
    thank you

Sign In or Register to comment.