Ellipsis for multiple columns

Ellipsis for multiple columns

colbrothcolbroth Posts: 3Questions: 3Answers: 0

I was attempting to use the DataTables configuration to use ellipsis for long names on multiple columns as show in your example at https://datatables.net/reference/option/columns.render. If I set targets to multiple columns (i.e. targets: [0,1]), it will duplicate the column values. For instance, setting targets to [0,1] will put all the values from column 1 into column 0.

See fiddle at http://jsfiddle.net/colbroth/Leo3xvwz/.

Could you please direct me to a solution where I can set the multiple columns to use ellipsis? I would like a generic solution since our application has multiple tables and only certain columns will have long names. The tables differ in which columns have long names.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,947Questions: 26Answers: 4,876
    Answer ✓

    I think it will work correctly if you remove the 'data' option:

          "columnDefs": [ {
            "targets": [0,1],
            "data": "description",   <<< remove this line
            "render": function ( data, type, row, meta ) {
              return type === 'display' && data.length > 20 ?
                '<span title="'+data+'">'+data.substr( 0, 18 )+'...</span>' :
                data;
            }
          } ]
    

    It seems that is setting the data source to description for both columns causing them to have the same data.

    Kevin

  • allanallan Posts: 62,819Questions: 1Answers: 10,332 Site admin

    It seems that is setting the data source to description for both columns causing them to have the same data.

    That's exactly what it is doing.

    You can have multiple columnDefs objects for a single column, so you could list the columns.data option in a different object, but for that sort of thing I tend to use columns for the individual properties and columnDefs for the grouped ones.

    Allan

This discussion has been closed.