Jump to content

Min/Max logic problem


pr0c3ss

Recommended Posts

If the logic of finding values between a min max range =

var min = parseInt( $('#min').val(), 10 );
        var max = parseInt( $('#max').val(), 10 );
        var page = parseFloat( data[11] ) || 0; 
 
 
    if ($("#in-range").is(':checked')){
        if ( ( isNaN( min ) && isNaN( max ) ) ||
             ( isNaN( min ) && page <= max ) ||
             ( min <= page   && isNaN( max ) ) ||
             ( min <= page   && page <= max ) )
        {
            return true;
        } 

 ... what's the logic of displaying values that fall outside of given min/max ranges?

for ex.  Table holds data 1-9.  

Min range = 3

max range = 7

 

the return should be 1,2,3,7,8,9

Link to comment
Share on other sites

The code example returns values that fall within the if statement (within entered min and max values)...which works fine...

 

I have been trying to amend this, so it return values that fall outside of a given min and max range.  So if table holds data 1-9 and some enters min 3 and max 7 as a range - the return should be 1,2,3,7,8,9

Link to comment
Share on other sites

If it correctly returns true for values inside the range, and you want it to now return false for values outside the range, I would expect that all you'd have to do is do an else { return false; }.

 

If that's not it then,

 

What table? What data? Where are all those values coming from? How is the function supposed to return both true/false and something like "1,2,3,7,8,9" (which I assume is either a string or an array)?

All that your code demonstrates is

1. Get the min and max values from the form.

2. Get data item 11 (whatever that means) as the page number.

3. Return true if the min and max fit those criteria.

Link to comment
Share on other sites

var page = a column in a html table

 

perhaps if I link you this example
https://datatables.net/examples/plug-ins/range_filtering.html

 

This searches within a range - like above.  I need the search to search outside of the range.  So if min and max entered values are 3-7...and page column holds 1-10.... 1,2,3,7,8,9 should return

Edited by pr0c3ss
Link to comment
Share on other sites

var page = a column in a html table

No, it's a float value.

 

This searches within a range - like above.  I need the search to search outside of the range.  So if min and max entered values are 3-7...and page column holds 1-10.... 1,2,3,7,8,9 should return

Okay. Like I said: you have a function that returns true if something is inside the range, so it should be a simple matter to make it return true if something is outside the range. Change your comparisons so that the page value is = max.
Link to comment
Share on other sites

if ( ( min <= page && page >= max ) )
        {
            return true;
        }

full function...

$.fn.dataTable.ext.search.push(
    function( settings, data, dataIndex ) {
		
		var inR = document.getElementById("in-range");
		var outR = document.getElementById("out-range");
		
        var min = parseInt( $('#min').val(), 10 );
        var max = parseInt( $('#max').val(), 10 );
        var page = parseFloat( data[11] ) || 0; 
 
 
    if ($("#in-range").is(':checked')){
		console.log('inrange active');
        if ( ( isNaN( min ) && isNaN( max ) ) ||
             ( isNaN( min ) && page <= max ) ||
             ( min <= page   && isNaN( max ) ) ||
             ( min <= page   && page <= max ) )
        {
            return true;
        }
	}
	else{
		console.log('outrange active');
        if ( ( min <= page && page >= max ) )
        {
            return true;
        }
	}
	
        //return false;
    }
  );

	var table = $('#output').DataTable();
	$('#min, #max').keyup( function() {
			table.draw();
	});
  });
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.