jQuery DataTables fixed size for ONE of the columns?

左心房为你撑大大i 提交于 2019-11-29 17:08:36

If you want precise control over the table column widths you must use CSS:

table.dataTable thead th:nth-child(4),
table.dataTable tbody td:nth-child(4) {
  width: 200px;
  max-width: 200px;
  min-width: 200px;
}  

If you inspect the above column you will see the that computed width is larger than 200px. This is the padding kicking in, so you must reset padding-left and padding-right to get exactly 200px.

If you want to shrink a column to a width beyond "reasonable" you must add som additional CSS :

table.dataTable {
  table-layout: fixed;
}

Why this is needed you can read about here -> https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout#Values

table.dataTable thead th:nth-child(2),
table.dataTable tbody td:nth-child(2) {
  word-break: break-all;
  overflow-wrap: break-word;
  width: 20px;
  max-width: 20px;
  padding-right: 0px;
  padding-left: 0px;
}

demo -> http://jsfiddle.net/n4j1wgu5/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!