sorting question

sorting question

ahuangahuang Posts: 5Questions: 0Answers: 0
edited May 2011 in General
Hi,

Just discovered this. Great job! Doing html sorting on a table. Is there built in way to trim leading white spaces in the td cells after the html has been removed?

Thanks!

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Are you using the 1.8 beta? I think I might have a small regression issue there - I've not a note to myself to look at that tomorrow morning :-). That should certainly be reverted back to the 1.7 trimming behaviour.

    Allan
  • ahuangahuang Posts: 5Questions: 0Answers: 0
    I'm actually using 1.7.6

    I end up with a td tag that looks something like this:

    [code]
    word
    [/code]

    That leading whitespace messes up the sorting.

    Thanks!
  • ahuangahuang Posts: 5Questions: 0Answers: 0
    To add additional context, the users are adding that white space by mistake. Want to have it trimmed prior to sorting.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    It looks fine to me in both 1.8 beta 3 and 1.7.6 - when reading from the HTML source the data is being trimmed so white space shouldn't matter. Can you give us a link to your example which isn't working please?

    Allan
  • ahuangahuang Posts: 5Questions: 0Answers: 0
    Here's the html I'm using. Trying to sort by the first column. If you look at the second row:

    PA-10-064

    There is an extra whitespace after the tag. It sorts correctly after it's removed. Thanks!

    [code]



    one
    two
    three
    four




    BAA -- Broad agency announcements are not included in this list. Find them here: NIAID Solicitations.
    DAIDS, DAIT, DMID
    Contract
    N/A




    PA-10-064, NIH Small Research Grant Program (Parent R03)

    NIAID Statement of Interest. May change; check the latest version.

    DAIDS, DAIT, DMID
    R03
    Standard dates through
    2013-01-08.



    RFP -- Requests for proposals are not included in this list. Find them here: NIAID Solicitations.
    DAIDS, DAIT, DMID
    Contract
    N/A


    BAA -- Broad agency announcements are not included in this list. Find them here: NIAID Solicitations.
    DAIDS, DAIT, DMID
    Contract
    N/A




    [/code]

    Thanks!
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Thank you for that - I see what the problem is. DataTables is trimming the data prior to the sort parsing (the removal of the HTML) so if your space was on the other side of the P tag it would be removed - but it's being considered part of the data here - hence the sorting order.

    Id suggest having a custom sorting function ( http://datatables.net/plug-ins/sorting ) which does the same as the DataTables default string sort, but adds a $.trim() call - or even use a plug-in to replace the default string sorting. I don't particularly want to add that into the DataTables core since it's extra overhead that won't be used the majority of the time (this is the first time I've come across this issue).

    In 2.x I plan to have a callback to make this kind of this a little easier - but that's probably a good little while away :-)

    Allan
  • ahuangahuang Posts: 5Questions: 0Answers: 0
    Ok I'll try to create a custom sorting function. Thanks for the quick responses.
This discussion has been closed.