Getting the number of rows in the main query of a grid app

I’ve the next issue: I’d like to get by some scriptcase variable the number of rows that return the main query in a grid app. I need this information to compare with a value in order to disable the add button. There’s any way to do that or I’m forced to apply a sc_lookup with an internal query to know that?


{count_ger} should work in the onHeader event.

That’s great, but the event you mention is the onFooter, not the onHeader. Wait until I test to tell you if it works fine. Thanks a lot.

That works (but only in the onFoot event, not the onHeader), but the problem I have is that I wante to get on the onScriptInit, because I need to hide the new button depending the number of records returned by the query. but it’s nos porrible to call the sc_btn_disable and the variable {count_ger] on the same event, what a shame. But thanks a lot, equally!

I don’t know why {count_ger} is not working for you in the onHeader event, but I just double checked and it does work in the onHeader event.

EDIT - If I remember correctly, the onHeader\onFooter events are triggered only if they are set to be visible in Layout>Header&Footer; so maybe you turned off the Header visibility?

Anyway, to hide elements when an SC macro is not available, you can always try JS or jQuery.

This is something I used on a grid onHeader event, to conditionally hide\show elements according to the number or rows:[INDENT]if < 10 records, hide refined search - using jQuery
if < 15 records, hide quick search - using an SC macro[/INDENT]The selectors to use in jQuery, i.e. $(’#ELEMENT_SELECTOR’), are easy discoverable using a browser inspector. Sometimes you need to work on more than one element to hide what looks like a single object on the web page.

if ({count_ger} <10)
echo '<script>
   $( document ).ready(function() {
   $(".scGridLabelLink img").remove();
else if ({count_ger} <15)

Sorry to tell that, it works fine (but according to scriptcase it shouldn’t work there on grid apps). The problem is that I’d need to use in the onScriptInit event, due my purpose is to use the sc_btn_display macro depending the value of {current_ger}, and it’s not possible then to do that. Yes, I know that I could use this detecion on the onFooter by using javascript code, but that is a idea that I don’t like too much, finally i’ve solved by getting the num_rows directly from a query in the onScriptInit event.
Thanks again!

I used jQuery only with one of the items I wanted to hide (Refined search) that was not controllable via SC macros.

As shown in the code snippet in my previous post: in the onHeader event you can read the the number of rows using the {current_ger} var and therefore conditionally hide\show buttons using the sc_btn_display() macro.

But maybe in your specific case you need to do it differently.

One hint: the SC help on macro\var scopes is not reliable at all: before ruling a solution out because of it, you’d better try it, regardless of what the help says.