I am using datatables
- as per documentation, it says to use
columns.width
option to control column width
- when I use
columns.width
and render table, it ignores this width and uses its own width
JSFIDDLE:
https://jsfiddle.net/bababalcksheep/bvgu0cL3/28/
- I am using 2 columns with long strings to test if i an apply width to it
- column name has long string without spaces
- column description has long string with spaces
- I am trying to apply width 200px to name column
Question:
what is the point of this columns.width
if table will still enforce its own width
how can I apply width 200px to name column and see it in action ?
JS:
$(document).ready(function() {
var table = $('#example').DataTable({
'autoWidth': false,
'scrollX': 'true',
'scrollY': 300,
'scrollCollapse': true,
columns: [{
data: 'name',
title: 'Long Name Issues',
width:'200px',
render: function(data) {
return '<span class="">'+ data + '</span>';
}
}, {
data: 'position',
title: 'Position'
}, {
data: 'description',
title: 'Long Description Issues',
width:450,
render: function(data) {
return data;
}
}, {
data: 'salary',
title: 'salary May have Big Title'
}, {
data: 'age',
title: 'age'
}],
data: [{
name: 'DavidDavidDavidDavidDavidDavidDavidDavidDavidDavidDavidDavidDavidDavidDavidDavidDavid',
position: 'CTO',
description: 'CTO',
salary: '1000',
age: '44'
}, {
name: 'John',
position: 'tech',
description: 'description',
salary: '1000',
age: '22'
}, {
name: 'Amber',
position: 'CEO',
description: 'SOME long description with spaces SOME long description with spaces',
salary: '1000',
age: '45'
}],
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…