I am using datatables
columns.width option to control column widthcolumns.width and render table, it ignores this width and uses its own widthJSFIDDLE: https://jsfiddle.net/bababalcksheep/bvgu0cL3/28/
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'
    }],
  });
});
The width property is merely useful for overall relative widths. In your case you also have a word-wrap issue. Define a CSS class and apply it to the column:
.px200 {
  width: 200px;
  max-width: 200px;
  word-wrap: break-word;
}
columns: [{
  data: 'name',
  title: 'Long Name Issues',
  className: 'px200', //<----
  render: function(data) {
    return  '<span class="">'+ data + '</span>';
  }
}
updated fiddle -> https://jsfiddle.net/bvgu0cL3/30/
Since you are wrapping the content into a <span> you might consider adding a class to that <span> instead of the <th> and <td>'s which className does. 
If you want total control over the widths, see this answer -> jQuery DataTables fixed size for ONE of the columns?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With