Can dataTables sort price range column

Can dataTables sort price range column

lprangerlpranger Posts: 11Questions: 1Answers: 0

A simple example is this of a column before an asc and desc sort

$129 – $169
$135
$80.11 – $98.11
$109
$102.60 – $125.11

I can't find or figure out a working example

This question has an accepted answers - jump to answer

Answers

  • lprangerlpranger Posts: 11Questions: 1Answers: 0

    I retyped the numbers in a column sorry


    A simple example is this of a column before an asc and desc sort

    $129 – $169

    $135

    $80.11 – $98.11

    $109

    $102.60 – $125.11

    I can't find or figure out a working example

  • rhinorhino Posts: 80Questions: 2Answers: 17

    So some cells of the table contain text of the form "$123.45 - $234.56"?

  • lprangerlpranger Posts: 11Questions: 1Answers: 0

    Yes, exactly.

    I would like to sort like this

    $40

    $45.25 - $50.00

    $80.11 - 98.11

    $95

    $102.60 - $125.11

    $525.22

  • rhinorhino Posts: 80Questions: 2Answers: 17

    Seems to just work for me... I have an example here

    Can you modify that to show the problem you're having?

  • lprangerlpranger Posts: 11Questions: 1Answers: 0

    I added to your set up, about 6 rows of data. The rows are added via the back end and I am just applying the datatable js with the proper init options.

    It's different how you were loading the data.

    It's pretty straight forward.

  • lprangerlpranger Posts: 11Questions: 1Answers: 0

    Sorry Rhino,

    I believe this is my example.

    http://live.datatables.net/cipecex/1/edit

  • lprangerlpranger Posts: 11Questions: 1Answers: 0

    Rhino,

    Did you have a chance to check out my example?

  • rhinorhino Posts: 80Questions: 2Answers: 17

    Hi Ipranger, I'm sorry for the long delay! I let it drop off my radar :(

    Anyway, I think I may have found a fix for you. I modified your example, and it seems to work. How's that look?

  • rhinorhino Posts: 80Questions: 2Answers: 17
    edited July 2014 Answer ✓

    Oh, and the render function can be shortened to:

    render: function( data, type, row, meta ) {
            if (type == "sort" || type == "type")
               return parseFloat(data.replace(/[$,]/g, ''));
            else
              return data;
          }
    
  • lprangerlpranger Posts: 11Questions: 1Answers: 0

    Thanks a Bunch!!!

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    @rhino - nice solution using orthogonal data. I was going to suggest using a plug-in sorting data type, but this is a nice way of doing it.

    Allan

This discussion has been closed.