Sunday, October 16, 2016

how to conditionally hide a DevExpress grid if the model bound (a collection) has no records BUT NOT WHEN FILTERING ROWS HIDES ALL ROWS

We need something like this, but more complicated, and so...

s.SetVisible ( s.GetVisibleRowsOnPage() > 0 );

 
 

...should be replaced with handing s into a more complicated function.

function MaybeHide(s) {
   if(s.GetVisibleRowsOnPage() > 0) {
      s.SetVisible(true);
   } else {
      var actors = $('input[type=text]').toArray();
      var isFiltering = false;
      for (var i=0; i < actors.length; i++) {
         if(i !=0 && i != (actors.length-1)){
            if (actors[i].value) {
               isFiltering=true;
            }
         }
      }
      if(!isFiltering) {
         s.SetVisible(false);
      }
   }
}

 
 

Above:

  • for (var i=0; i < actors.length; i++) { checks to see if a field for filtering is doing its thing, but not every field. We are making some assumptions and only checking to see if the fields which are not the first and last field have copy in them. The last field is likely the pagination drop down. The first field in this example? Oh, perhaps a different control elsewhere on the page. This has to be set on a case-by-case basis. Tailor it to your stuff!
     
  • if (actors[i].value) { is going to be falsey if the filter field is empty and truthy otherwise. Get it?

No comments:

Post a Comment