Ok - you can do it this way (see picture for how this looks)…
First add a field, e.g. “delete” of type HTML Image. Leave everything else as default (and the image field blank). In Field Positioning move the “delete” field to the top.
Then in the grid’s onScriptInit:
$sqlq = "SELECT COUNT(*) FROM tblxxxxxxx WHERE xxxxxx"; // Duplicate the grid's overall query with relevant WHEREs etc to get the grid's record count
sc_lookup(my_data, $sqlq);
if ({my_data} === false) {
echo "<script type='text/javascript'>alert('DB Access error. Message = " .
{my_data_erro} . "');</script>";
[last_record] = 0;
} else {
[last_record] = {my_data[0][0]};
}
[rec_pos] = 0;
Make sure, after saving the app, to set the 2 global variables (rec_pos and last_record) just defined above in Application => Global Variables as type “out”.
Then in onRecord:
[rec_pos] += 1;
if ( [rec_pos] == [last_record] ) { // if last record only
{delete} = "<img src='../_lib/img/scriptcase__NM__ico__NM__trash.gif' alt='Delete' title='Delete' >"; // Assign "trash" image to just that record
} else {
{delete} = '';
}
Now create an Ajax event for the “delete” field of type onClick. Select the key / id field to pass as a parameter. In the code window enter the code you want processed, i.e. delete that record. To test the functionality I used below (but you will need to add your own PHP delete code for the record - can’t do it ALL for you ;)):
echo "hello " . {fffffff}; // ffffff = a visible field name
Now, if the grid is paginated (which is the default) and your last record is not on the first screen it doesn’t work (for some reason) - not sure why and not had the time to look into it. To get around this though, turn off pagination (in Grid Modules, click on Grid on the right and set pagination to Total) - but again, I’ll leave it to you to tweak it t work with pagination if it’s needed.
That’s it.
