javascript - How do I fix long column value issue which breaks table outside of container, using DataTables.net? - Stack Overflo

When one column has a long value, without spaces, the table breaks out of any container with a set widt

When one column has a long value, without spaces, the table breaks out of any container with a set width (or percentage). Currently, I'm needing a table with 50% width, and the long value breaks the table out of the 50% width container.

This jsFiddle simplifies my issue, with a width of 70%, and any custom CSS I've used overriding typical DataTables CSS (besides visual styling).

/

HTML:

<div class="container">
  <table class="grid"></table>
</div>

CSS:

.dataTable {
  width: 100% !important;
  margin: 0;
}
.dataTables_wrapper {
  position: relative;
}
.dataTables_scrollHeadInner {
  width: 100% !important;
}
.container {
  position: relative;
  width: 70%;
  border: 1px solid #f0f;
}
.container .grid {
  position: relative;
  overflow-x: hidden;
}

Note: I realize I shouldn't use !important, but that's an issue for another day.

Please see the jsFiddle for the specific JS, and DataTables options I'm using.

I'd like to cut off/truncate the long value with ellipses using CSS. I probably need something like:

.dataTable tbody td {
  text-overflow: ellipsis;
  overflow: hidden;
}

The only solution that's worked for me is to have a div in the td and setting a max-width/width on the div, but I don't want to set a fixed width, since I want it to be figured out from DataTables options, using the sWidth option.

I've done some research, but haven't e up with any solid solutions yet. Does anyone have a solution for this?

When one column has a long value, without spaces, the table breaks out of any container with a set width (or percentage). Currently, I'm needing a table with 50% width, and the long value breaks the table out of the 50% width container.

This jsFiddle simplifies my issue, with a width of 70%, and any custom CSS I've used overriding typical DataTables CSS (besides visual styling).

http://jsfiddle/mswieboda/8qVh4/

HTML:

<div class="container">
  <table class="grid"></table>
</div>

CSS:

.dataTable {
  width: 100% !important;
  margin: 0;
}
.dataTables_wrapper {
  position: relative;
}
.dataTables_scrollHeadInner {
  width: 100% !important;
}
.container {
  position: relative;
  width: 70%;
  border: 1px solid #f0f;
}
.container .grid {
  position: relative;
  overflow-x: hidden;
}

Note: I realize I shouldn't use !important, but that's an issue for another day.

Please see the jsFiddle for the specific JS, and DataTables options I'm using.

I'd like to cut off/truncate the long value with ellipses using CSS. I probably need something like:

.dataTable tbody td {
  text-overflow: ellipsis;
  overflow: hidden;
}

The only solution that's worked for me is to have a div in the td and setting a max-width/width on the div, but I don't want to set a fixed width, since I want it to be figured out from DataTables options, using the sWidth option.

I've done some research, but haven't e up with any solid solutions yet. Does anyone have a solution for this?

Share Improve this question asked Oct 24, 2013 at 16:04 mswiebodamswieboda 1,0362 gold badges10 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Add this CSS. The CSS must be applied before the table is renderd.

table { table-layout: fixed; }

td { 
 overflow: hidden;
 text-overflow: ellipsis; 
}

jsfiddle

If you don't really need to show ellipses, you can force a line break inside the td.

table { table-layout: fixed; }
td { word-wrap:break-word; }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745134443a4613132.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信