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

rqwerty
  • 13
  • 4
  • I have not used `sigma` but `indexOf()` is a common function that returns `-1` when it doesn't find anything. And `indexOf()` is often used for finding or counting things. Try searching for occurrences of that in your code or the library functions you are using. – Seth Holladay Jan 06 '17 at 09:46
  • yes, we have indexof code in plugin, can you please check plugin code here : http://pastebin.com/ftfL6qnU – rqwerty Jan 06 '17 at 10:59
  • i found 4 occurances, what i need to do now.... – rqwerty Jan 09 '17 at 05:32

1 Answers1

0

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.
myfunkyside
  • 3,890
  • 1
  • 17
  • 32