jquery datatables word wrap不工作。

时间:2022-11-29 10:55:26

My datatable's column looks wider if the value is too long.

如果值太长,则datatable的列看起来更宽。

jquery datatables word wrap不工作。

i have following this and this. And setting the width :

我跟踪这个和这个。设置宽度:

aTable = $("#printdata").dataTable({
     "bAutoWidth" : false,
     "bRetrieve"  : true,
     "scrollY": 200,
     "scrollX": true,
     "deferRender": true,
     "scroller": {
          loadingIndicator: true
          },
     "bServerSide": true,
     "bProcessing": true,
     "sAjaxSource": 'show2ndsampling.php',
     "fnServerData": function (sSource,aoData,fnCallback){
          $.ajax({
                   "dataType":'json',
                   "type":'POST',
                   "url":sSource,
                   "data":aoData,
                   "success":function(json){
                          fnCallback(json);
                          }
                   });
          },
    "order"  : [[1,"desc"]],
    "aoColumns"  : [
    /*serial*/{ "width": "30%", target : 3 }
    ]

But there is no change in my datatable.

但是我的datatable没有变化。

3 个解决方案

#1


3  

I would do this

我将这样做

table.dataTable tbody td {
  word-break: break-word;
  vertical-align: top;
}

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

演示- > http://jsfiddle.net/qh63k1sg/

This is implied that autoWidth is set to false and you have given the columns a fixed width (as in the demo and as OP have described he does with aoColumns / columns).

这意味着autoWidth将被设置为false,并且您已经为列设置了一个固定的宽度(如在演示中和OP中描述的,他对aoColumns / columns所做的)。

#2


1  

For now, I can tell you, that the best way for displaying data is modifying your output.

现在,我可以告诉您,显示数据的最佳方式是修改输出。

It means:

它的意思是:

  1. if you create response on base of sql query -> you should optimize it and add a space in your quesry.
  2. 如果您在sql query ->基础上创建响应,您应该优化它并在您的问题中添加一个空格。
  3. If you do it in template -> prepare data on templeate part, example on PHP
  4. 如果您在template ->中编写templeate部分的数据,请参见PHP示例
  5. If you do it on frontend part, make it in JS way.
  6. 如果你在前端部分做,用JS的方式做。

PHP way :

PHP:

$result = array( /* your result */);
foreach($result as &$answer ){
   $answer = implode( ", ", explode( ",", $answer) );
}

JS way :

JS:

var result = [/* your result */];
for( var index = 0; index < result.length; i++ ){
  result[index] = result[index].split(",").join(", ");
}

#3


0  

You can fix this with css.

你可以用css来解决这个问题。

table /* give class of table*/
{
   table-layout: fixed;
}

table td
{
  word-wrap:break-word;   
  overflow: hidden;
}

#1


3  

I would do this

我将这样做

table.dataTable tbody td {
  word-break: break-word;
  vertical-align: top;
}

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

演示- > http://jsfiddle.net/qh63k1sg/

This is implied that autoWidth is set to false and you have given the columns a fixed width (as in the demo and as OP have described he does with aoColumns / columns).

这意味着autoWidth将被设置为false,并且您已经为列设置了一个固定的宽度(如在演示中和OP中描述的,他对aoColumns / columns所做的)。

#2


1  

For now, I can tell you, that the best way for displaying data is modifying your output.

现在,我可以告诉您,显示数据的最佳方式是修改输出。

It means:

它的意思是:

  1. if you create response on base of sql query -> you should optimize it and add a space in your quesry.
  2. 如果您在sql query ->基础上创建响应,您应该优化它并在您的问题中添加一个空格。
  3. If you do it in template -> prepare data on templeate part, example on PHP
  4. 如果您在template ->中编写templeate部分的数据,请参见PHP示例
  5. If you do it on frontend part, make it in JS way.
  6. 如果你在前端部分做,用JS的方式做。

PHP way :

PHP:

$result = array( /* your result */);
foreach($result as &$answer ){
   $answer = implode( ", ", explode( ",", $answer) );
}

JS way :

JS:

var result = [/* your result */];
for( var index = 0; index < result.length; i++ ){
  result[index] = result[index].split(",").join(", ");
}

#3


0  

You can fix this with css.

你可以用css来解决这个问题。

table /* give class of table*/
{
   table-layout: fixed;
}

table td
{
  word-wrap:break-word;   
  overflow: hidden;
}