jQuery - 数据表排序后不保留列宽

发布于 2024-12-10 23:53:51 字数 378 浏览 0 评论 0原文

我有一个 jQuery 数据表,我指定了列宽,如下所示:

"aoColumnDefs":[
  { "sWidth":"40%" },
  { "sWidth":"10%" },
  { "sWidth":"50%" } ]

我还指定了 CSS 样式,如:

  td { position: relative, word-wrap: break-word; }

该表完全按照我想要的方式显示,长条目已被包装。但是,当我对第二列进行排序时(排序由后端服务器处理),第一列的一些值很长,但从未中断和换行。该表仅显示一列(由于值的最长长度超出了表宽度)。

如何让数据表遵守初始化的宽度并正确渲染?

I have a jQuery data-table which I specified the column width likes following:

"aoColumnDefs":[
  { "sWidth":"40%" },
  { "sWidth":"10%" },
  { "sWidth":"50%" } ]

I also specified the CSS style like:

  td { position: relative, word-wrap: break-word; }

The table displays exactly as I wanted, long entries have been wrapped. However, when I sorted on the second column (the sorting is handled by the back-end server), some of the values of the first column are long but never broke and wrapped. The table showed only one column (due to the longest length of the value exceeded the table width).

How can I get the data-table obey the initialized width and render correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2024-12-17 23:53:51

您可以尝试使用该列中单元格的 sClass 属性来设置样式,转到此处 http://datatables .net/ref 并向下滚动 sClass 引用。

"aoColumnDefs":[
  { "sWidth":"40%", "sClass":"relative-postition-and-break-word" },
  { "sWidth":"10%", "sClass":"relative-postition-and-break-word" },
  { "sWidth":"50%", "sClass":"relative-postition-and-break-word" } ]

(长类名只是为了让大家明白你的类将有什么CSS)

You can try using the sClass property of the cells in that column to style go here http://datatables.net/ref and scroll down the the sClass reference.

"aoColumnDefs":[
  { "sWidth":"40%", "sClass":"relative-postition-and-break-word" },
  { "sWidth":"10%", "sClass":"relative-postition-and-break-word" },
  { "sWidth":"50%", "sClass":"relative-postition-and-break-word" } ]

(The long class name is just to get the point across as to what your class would have as css)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文