Leading spaces are getting trimmed for table data

Leading spaces are getting trimmed for table data

TheGigglerTheGiggler Posts: 6Questions: 0Answers: 0
edited January 2013 in General
Hi!

I'm new to DataTables and it's been great and pretty easy to integrate into my app!

One quirk I've found is that, in table cells, strings that have leading spaces are being displayed without them, which could be confusing when displaying in a sorted grid.

I should note that I am doing all my sorting and paging server side and passing the aaData back via JSon, so the sort order is correct, with the strings with leading spaces in the database appearing at the top of the list, but with the leading space trimmed off, making them appear out of order when displayed.

Examining the Json via Fiddler the leading spaces are retained on the data I'm returning to the client.

I looked in the style sheets and couldn't find anything that might trim the spaces.

Am I missing something obvious?

Thanks!

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited November 2019
    DataTables does do a trim on data when it is being taken from an DOM source, since the majority of the time white space is not wanted - for example:

    [code]

    words

    [/code]

    Has a \n and four spaces before `words` - which shouldn't be taken into account for sorting etc.

    You can disable that trim, if you need to do so, by altering this line in DataTables: https://github.com/DataTables/DataTablesSrc/blob/5b2708dd876696311f76d20d26c2e312a3611041/js/core/core.data.js#L621

    Allan
  • TheGigglerTheGiggler Posts: 6Questions: 0Answers: 0
    Thank you, I will try that!
This discussion has been closed.