9

How do I set a max width for one specific column, all the other columns should be auto sized. I have tried the below code, but it does not work since I think there is no 'max-width' attribute

$('#table').dataTable({
    'paging': false,
    'info': false,
    'searching': false,
    'columnDefs': [
      {'max-width': '320px', 'targets': 'my-column'}
    ],
});
4
  • can you check with my answer ? Commented Mar 3, 2016 at 5:52
  • max-width does not work for me. Also targets can be a css class of a column, not only an index Commented Mar 3, 2016 at 8:27
  • No need mention class name in target option, just mention position number of column, I test with my project, that is working fine Commented Mar 3, 2016 at 8:34
  • why not use the index of field in datatable ? Commented Mar 5, 2016 at 11:59

1 Answer 1

-2

Try something like this

max-width option mention the width percentage

targets option mention index of field

$('#table').dataTable({
    'paging': false,
    'info': false,
    'searching': false,
    'columnDefs': [
      {'max-width': '20%', 'targets': 0}
    ],
});
Sign up to request clarification or add additional context in comments.

2 Comments

I don't think columnDefs contains a 'max-width' property, so this might not work... datatables.net/reference/option/columnDefs
As mentioned by @Bartosz, I could not see any max-width option. If it exists in any of the version, please flag the version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.