abbreviate long text fields

abbreviate long text fields

luc2luc2 Posts: 3Questions: 0Answers: 0
edited November 2012 in General
hello,

is it possible to abbreviate long text fields ?

for example, display

[code]long t...[/code]

instead of

[code]long text field long text field long text field long text field long text field long text field long text field long text field[/code]

Replies

  • jefffan24jefffan24 Posts: 18Questions: 0Answers: 0
    This isn't a datatables thing, but there is a plugin called jTruncate

    http://www.jeremymartin.name/projects.php?project=jTruncate

    You can use it in datatables by adding the following options to the initialization (im building these as if it is the only column, please adjust it for your needs):

    [code]
    "aoColumns" : [
    {
    mData: null,
    sClass: "longTextClass"
    }
    ],
    "fnDrawCallback": function( oSettings ){
    $('.longTextClass').jTruncate();
    }
    [/code]

    Putting it in the fnDrawCallback will allow it to update every time the table is re-drawn (which is when it needs to be run).
  • j7mboj7mbo Posts: 7Questions: 0Answers: 0
    edited November 2012
    What you really want to use is [code]text-overflow:ellipsis;[/code]

    See: http://www.css3.info/preview/text-overflow/

    Although this might be a problem in tables, it's worth the look anyway :)
  • luc2luc2 Posts: 3Questions: 0Answers: 0
    thanks very much
  • jefffan24jefffan24 Posts: 18Questions: 0Answers: 0
    To add onto what j7mbo said, if you know your target audience will support it use it. But if your like me and you just don't know what kind of browsers your going to have I don't risk it and use jTruncate.
This discussion has been closed.