Filter Datatable for a numeric condition using greater than operator

Filter Datatable for a numeric condition using greater than operator

cpshartcpshart Posts: 246Questions: 49Answers: 5

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Hi

I need to create a button to filter a Yield column in the datatable where there are three conditions namely

Button Display
Yield, no filter applied, ALL 
Yes, Yield > 0.00
No, Yield = 0.00 

I have created a JS Bin test based upon the one given below

http://live.datatables.net/rowakuju/20/edit

My test system is here

http://live.datatables.net/cupukaca/1/edit?html,css,js,console,output

My JS section of additional code to the first test case

      {
        text: 'Yield',
        action: function ( e, dt, node, config ) {
          var text = this.text();
            console.log('text:',text);
          var search = '';
          
          if (text === 'Yield') {
            this.text('Yes');
            search = '4';
          }
          else if (text === 'Yes') {
            this.text('No');
            search = '0.00';
          }
          else {
            this.text('Yield');
            search = '';
          }
          
          table.column(5)
                    .search(search)
                    .draw();
            
        }

The problem is that the search is looking for an exact match on a string value, but in this case I need to check a simple numeric condition on the Yield Column, hopefully this should be very straight forward.

this code section needs to effectively search > '0.00', operators like > however are not supported in this construct when dealing with strings.

          if (text === 'Yield') {
            this.text('Yes');
            search = '4';
            console.log('11111');

Many Thanks

Colin

Replies

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Creating a search plugin is probably the best way. This example might get you started.

    Kevin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi Kevin

    Thanks for your quick response, I will take a look at the search plugin.

    Best regards

    Colin

This discussion has been closed.