Not sure I get exactly what you're trying to do with the 'row number' but I would just place a counter inside an ondata function and reset on a change of category
By way of example - a code block I use to keep running totals inside categories...
| function reservation_balance($BlockName,&$CurrRec,$RecNum){ global $balance; // need this so it's available for next calc ;-)
 $CurrRec['memberlogin']=="Minimum" ?  $balance = $CurrRec['quantity'] : $balance=$balance - $CurrRec['quantity'];
 $CurrRec['balance'] = $balance;
 }
 
 | 
and in the html, to cycle on the categories
| [blk.balance;block=footer;footergrp=resnumber] | 
HTH