[fpc-devel] fcl-web webdata ExtJS "total" field question

Michael Van Canneyt michael at freepascal.org
Thu Aug 19 23:59:19 CEST 2010

On Thu, 19 Aug 2010, ABorka wrote:

> ...snip...
>>> 2. How can I provide the correct "total" for the response if I only
>>> loaded exactly the records requested by ExtJS into the dataset but not
>>> the whole table?
>>> Ex: Have a table with 1000 records, I'm on page 2 of the grid that has
>>> a page limit of 50 records.
>>> Of the total 1000 records, only about one third should be visible for
>>> the person currently requesting data.
>>> Therefore, I run a SQL statement to get those next 50 records from the
>>> 333 potential ones for this person, and that will be displayed in the
>>> grid, and only those 50.
>>> This way, only I can tell in the response the correct "total", which
>>> is 333 in this case. 50 was passed to the formatter/adapter.
>> Well, I have no idea. As far as I know, the 'total' is only needed for
>> display purposes in a paging grid. You'd need to run a second query which
>> counts the number of records that would be returned if no paging was
>> requested.
>> Michael.
> Hi Michael,
> I understand.
> However, how do we send back our own "total" we got from our second query? 
> How do we append/update it into the response?

Good point.

> With XML, FCL-web always appends a "total" so that should be overwritten 
> somehow.
> I guess we can trick FCL-web to not append its own "total" with JSON by 
> sending only the 50 records needed and saying to it that the "start" is the 
> 1st one and "limit" per page is 51 even if those 50 come from a table of 1 
> million records.
> It seems we need to manipulate the tmemorystream that is generated by the 
> formatter? Maybe we should make this a little bit easier for developers 
> somehow.

Yes. I don't think you should manipulate the stream; it is too slow.

I will add an 'AfterFormatResult' or so event; 
Likewise I will add a AfterRow event, so it is possible to append extra data to a row. 
I think we should do this for both XML and JSON, so the row/response elements can easily 
be accessed. The question is now, 
a) do I make this a TNotifyEvent, and make a Property Response/CurrentRow which can be used
b) do I pass Response/CurrentRow to a new event handler type for these events ?

Doing a) means I can introduce it at a higher level, but b) seems more clean.


More information about the fpc-devel mailing list