Dynamically detect which column contains long text then do ellipsis on that column.
Dynamically detect which column contains long text then do ellipsis on that column.
![woodmanhu](https://secure.gravatar.com/avatar/3d392241d9f8fad3d9e16aaa20c8c5a8/?default=https%3A%2F%2Fvanillicon.com%2F3d392241d9f8fad3d9e16aaa20c8c5a8_200.png&rating=g&size=120)
So far I'm able to find the long text column by matching column names like :
$.each(TableColumns,function(id,name){
if(column_name == 'description'){
ColumnDefs.push({
targets: id,
render: $.fn.dataTable.render.ellipsis(20)
})
}
})
But most of time the table is generated dynamically. Columns are defined by previous selections.
I'm thinking a way to say:
$.each( data that is returned from ajax call, function(id, value){
if( value.length > 200 characters ){
ColumnDefs.push({
targets: id,
render: $.fn.dataTable.render.ellipsis(20)
})
}
})
But often time there are thousands of data being returned and looping one by one just for testing the length is not so efficient.
Is there a existed Option or plug-in to auto detect the length of data then do ellipsis for that column?
Answers
The best I can offer is that you modify the ellipsis plug-in so that you can give it a cut point (the 20) and also a cut off point (the 200 in this case) - so that the plug-in itself can use that conditional logic to decide when to activate or not.
Sounds like a useful extension to its current abilities!
Allan
Yes that's the same solution I realized as well. Thanks for your answer!