Datatable Search on decimal

Datatable Search on decimal

sathiyapriyasathiyapriya Posts: 4Questions: 1Answers: 0

I'm new to jquery datatable. I'm having a datatable. binding the values from DB to datatable. In loop binding the value to datatable. I'm having an amount column. This i want to show with $ symbol and comma for thousand and period for decimal. This i achieved by the format
item.claimAmount.ToString("$#,##.#0")

I have search for the same datatable. when i search an amount let say i type 123 then all the amount starts with 123 filtered. If i type like 1234, its not filter out the amount. i need to put comma 123,4 then its filter out. How can i achieve this.

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin

    I would suggest you use the number renderer that is built into DataTables for this.

    Allan

  • sathiyapriyasathiyapriya Posts: 4Questions: 1Answers: 0

    Hi Allan,

    If i implement the number renderer will search will work as expected. I want to search on amount user type 123 it should return the amount which matches 123.00 and 12,312.90 both. How can i achieve this. Currently i do search like below.

    function regex_escape(text) {
    return text.replace(/,/g, "").replace(/\./gi, "").replace(/\s+/g, "");
    };
    
    var query = regex_escape($(this).val());
     drejectTable.search(query, true, false).draw();
    
  • mikeosoftmikeosoft Posts: 40Questions: 14Answers: 2

    I don't know if it can help, but I came across this some time ago :

    https://datatables.net/examples/advanced_init/html5-data-attributes.html

    Looks like the data-search could do what you want.

  • sathiyapriyasathiyapriya Posts: 4Questions: 1Answers: 0

    Hi Mike

    Thanks, i had checked the link. The example provided in the link, the search not working as expected. need to use comma in search textbox. let say in search box if i type 86, datatable shows the record that matches. if i type 865 it not showing any records. but datatable has value of 86,500. So i search if i type 86,5, shows that record.

    Anyone can help me on this. Whether is this achievable in datatable or not.

  • sathiyapriyasathiyapriya Posts: 4Questions: 1Answers: 0

    Also the below link some solution is provided. But not sure how to implement that for may case.

    https://datatables.net/forums/discussion/15890/search-with-or-without-comma-dot-space

    Can some one guide me on this

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

    The code in that example should just slot into your case. We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.