Solution for Ellipsis - Jquery + Bootstrap + Datatables

Deadly 提交于 2020-01-15 09:43:07

问题


I am using Datatables on a site with bootstrap and jquery for a large (2000+ entries) table. Some of the (text) values are way too long and at the moment I use something like this:

render: function ( data, type, row ) {
                        return data.length > 35 ?
                        data.substr( 0, 35 ) +'…' :
                            data;
                    }

in Datatables to cut the strings and display the full value in the html title. Is there a better way to do this? Like a plugin that automatically cuts but shows all when clicked on or something similar? I was not able to find something.

I saw jquery dotdotdot but it doesnt give me a click to extend.


回答1:


Modifying strings in javascript in order to make them more viewable or "fitted" to certain DOM elements is a total no-go. Especially when you as here have many strings that is being preprocessed in a callback.

If you force fixed widths to some (or all) columns, example :

table.dataTable td:nth-child(3) {
  max-width: 100px;
}

Then you can use simple CSS to ensure that the content of the columns not is wrapped, not go beyond margins and displays a nice ellipsis if it is too large by

table.dataTable td  {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

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



来源:https://stackoverflow.com/questions/38347200/solution-for-ellipsis-jquery-bootstrap-datatables

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