如何将固定宽度设置为数据表列?

时间:2017-04-24 06:59:56

标签: jquery datatable

我知道之前已经在这里讨论了所以我先回答了所有答案,但仍有一些问题。

我有一个带有注释列的表,其中包含更多文本,其他...我希望将固定大小设置为所有列,并且仅为注释列设置不同的大小 - 或者只是为了打破行 - 不知道什么是最好的方式...希望你能帮助我。

我没有设法让这段代码发挥作用:

clear;
clc;   

t = -2:0.01:2;
x_1 = t.^2; x_2 = t.^4;

scf(0);
clf(0);
//plot the curves first to make legend easier
plot2d(t, [x_1', x_2'], [color('green'), color('red')]);
legend(['t^2'; 't^4']);   //the first two elements are the curves, so no neet to modify
ax = gca(); 
ax.auto_clear = 'off';
ax.data_bounds = [-3, 0; 3, 3];
ax.box = 'on'; 

xfpoly([-3 -2 -2 -3], [0 0 3 3], color('grey'));
xfpoly([2 3 3 2], [0 0 3 3], color('grey'));
xfpoly([-1 1 1 -1], [1 1 3 3], color('grey'));


scf(1);
clf(1);
xfpoly([-3 -2 -2 -3], [0 0 3 3], color('grey'));  //ymax sholud be 3, not 16
xfpoly([2 3 3 2], [0 0 3 3], color('grey'));
xfpoly([-1 1 1 -1], [1 1 3 3], color('grey'));
ax = gca(); 
ax.auto_clear = 'off';
ax.data_bounds = [-3, 0; 3, 3];
ax.box = 'on'; 

这是项目的一个示例(在生产中有更多列,文本更多)      Plunker

1 个答案:

答案 0 :(得分:4)

首先;你需要对你的css文件进行一些小改动;

#example > tbody > tr > td {
    white-space: nowrap;
}

将是;

#example > tbody > tr > td {
    word-break: break-all;
}

此更改将破坏长文本的界限。 如果您仍想更改特定列的宽度,则应使用 DataTables columnDefs属性。等;

"columnDefs": [{ "width": "200px", "targets": 3 }]

修改后的示例: Plunker