Search code examples
javascriptsigma-grid-control

empty results displaying count as -1 instead of 0


We are displaying count of results displayed based on "from & to date" search, we are facing issue that when there is empty results, than its displaying "-1" as result, but we want to display as "0"

html code is

<div class="delete_grid" >

<form name="frmSearch" method="post" action="">
<input type="text"  id="post_at" name="post_at"  />  
<input type="text"  id="post_at_to_date" value=""name="post_at_to_date"  />
<input type="submit" name="search" value="search" id="searchButton">

</form>

</div>

javascript code is

var gridOption={
    container : 'myGrid',
};

var mygrid=new Sigma.Grid(gridOption);
Sigma.Util.onLoad( Sigma.Grid.render(mygrid) );

$(".delete_grid").append("Number  of  Designs  Sold : "+mygrid.dataset.getSize());

we are using sigma plugin : http://pastebin.com/ftfL6qnU


Solution

  • Not sure where you're getting -1 exactly, I'm guessing here maybe: mygrid.dataset.getSize()?

    In any case, you can probably use a ternary operator.
    So let's say you need it there, use this: mygrid.dataset.getSize()<0?0:mygrid.dataset.getSize()

    The complete line would become:

    $(".delete_grid").append("Number  of  Designs  Sold : "+(mygrid.dataset.getSize()<0?0:mygrid.dataset.getSize()));
    
    • When mygrid.dataset.getSize() is less then 0, the value is set to 0.
      Otherwise, the value of mygrid.dataset.getSize() is used.
    • Notice that in the complete line, I wrapped the ternary operator in parentheses. It might not be strictly necessary, but when you're unsure or when it improves readability, I always prefer that.