How to update variable in Search Header (show records count)

Hello, I have a Grid, with initial module “Search”.

What I want to achieve is, show in the Grid Header (in my case is the Search Header, and the Grid header is hidden, but it doesnt matter for my issue I guess)
the number of records displayed!

It’s easy when you load the grid, it shows the correct number, but I want that when an user uses the filter, it updates that number in the header!!

my current code:

$where_clause = {sc_where_current};


$rowcount = " SELECT COUNT(*)
        FROM TblItemList
        $where_clause";

  sc_lookup(myrecord,$rowcount);


[Recordcount] = '('.{myrecord[0][0]}.')';


Then I use in the Header variable field this global variable.

It only works on the first load of the grid! It shows the correct amount of records.

But as soon as I use a filter and the grid is updated with less records,
it doesn’t update the value in the header,
and to be honest, I’m not even sure that {sc_where_current} is working after the initial load,

as I tried a var_dump with that global variable in every event of the grid and the search, and it never updates the variable value after the initial loading of the grid!

Maybe my attempt is wrong,

so does someone know how to show in the HEADER of a GRID, the CURRENT number of records displayed?

why not put your code in the search section/onvalidate event?

that was the first thing I tried!

The onFilterInit, onRefresh, onSave, onFilterValidate

nothing would work, and I’m not even sure {sc_where_current} works from those filter events, because it wouldn’t update the variable from what I saw

what version of SC you use?

latest one and fully updated (SC 9)

a small workaround I found was to activate in the toolbar the Row Counter button,

then onScriptInit event, change this:

{lang_othr_smry_info} = “?total? records”;

so now in the toolbar I have this string -> [X records], where X is the actual current number of records, accounting also for the filter!

This is almost a perfect solution, but the only thing is I cannot place this string in the Filter Header (z-index issue, if I change the relative position of it, and try to place it on top of the Filter header, it disappears because it has a lower Z-index, but I cannot change that as I need the filter header to be higher, so when you scroll the grid, it goes “behind” the filter header")

But anyway, this means that SC has somewhere a variable that stores the current record count…why cannot we have access to it?

Use CSS to change the Z-index to same value as filter

could you post a screenshot?

Hey, sorry missed your answers!

In what Event did you put that code?

Because if I just put it on “OnValide” in the “Search” Events, then it won’t work.
But if I put it also in “onScriptInit”, of the “Search” Events, it will just work for the initial value, but after I use the filters, it won’t update!

And also, I don’t know if you use the same structure in your grid, but mine has “Initial Module” as : Search, and “Use iFrame” set to YES.

So that means it opens the Search bar at the top, and below it the actual grid!

so I tried literally putting the code in every possible event of a grid, and it would work only on the first load, after that, on each change of the filter, the number wouldn’t update

perhaps you need to try to use AJAX macro