json type is float, how can I search "xxx.00"

json type is float, how can I search "xxx.00"

zyq105zyq105 Posts: 17Questions: 4Answers: 0

In my datatables, one of the column (price) json type is float, and I force it render it as "#.##" format. So, if the price value is 15, it will displayed as "15.00". Now, if I search "15.00" it does not show up.
My question is what I should do so that if somebody search "15.00", it will still show up?

        columnDefs: [
                        {
                            targets: [1],
                         render: $.fn.dataTable.render.number(',', '.', 2)
                        },
                       ],
                    columns: [
                        {data: "product"},
                        {data: "price"},

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Can you post the format of the original data, please, it'll help us understand the problem.

    Colin

  • zyq105zyq105 Posts: 17Questions: 4Answers: 0

    The origin json is like below. now, if I search"54.00" or "35.10", the items won't show up.

    "data": [
    {
    "product": "Apple",
    "price": 54
    },
    {
    "product": "Orange",
    "price": 35.1
    }
    ]
    
  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    The [Data Renderers docs}(https://datatables.net/manual/data/renderers) state this:

    The primary advantage of using a data renderer in DataTables is that you can modify the output data without modifying the original data

    You will need to use Orthogonal Data to alter the data to search on. You can use the same renderer with a chained display() method in columns.render to affect both the display and filter processes. See this example:
    http://live.datatables.net/ducuwixe/1/edit

    Kevin

  • zyq105zyq105 Posts: 17Questions: 4Answers: 0

    very nice! Thank you!

This discussion has been closed.