Delete only latest raw

Hi All,
I have Master details form, i want to give the user ability to delete only the latest record.
what i mean is to show the delete icon at the latest raw only and if he delete it, it will show at the previous raw only and so.

is it Possible with scriptcase ?

i am attaching photo to understand more what i am trying to get

Thanks in advanced

Best regards

Master.jpg

You can, but you have to do it playing with JavaScript I think, never tried something like this

try MAX with LIMIT 1 in SQL

Thank you Mike,
if you mean to put it from the start in sql
this will bring only 1 record , what i want is to bring all the data on screen, but limit the user to delete only the latest record from latest then previous.

it is very importing to do that because the latest record calculation is based on the previous record, and if the user delete somewhere in the start or middle, everything will be wrong!!

did anyone try to get this before ? any hints ?

regards

Thank you Giu,
the problem that i am not expert in JavaScript, if you manage to try something like this, please send me

Best regards

here is a new photo explain what i am trying to get

regards

delete.png

[QUOTE=walid;35377]here is a new photo explain what i am trying to get

regards[/QUOTE]

Oops, you mean only the icons (the functionality), not the whole records! plz ignore my previous reply then, lets try to think differently.

Will get back to you.

[QUOTE=walid;35377]here is a new photo explain what i am trying to get

regards[/QUOTE]

Oops, you mean only the icons (the functionality), not the whole records! plz ignore my previous reply then, lets try to think differently.

Will get back to you.

hi,
anyone knows how to do this ?

Regards,

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.

Capture.jpg

Thanks alot adz1111 ,

i will try to do it like you explain.

i will come with updates once done

regards

Hi adz1111 ,
to get the last record always on the first screen, ORDER BY id DESC.
now what i am getting when running only text <img src=’…/_lib/img/scriptcase__NM__ico__NM__trash.gif’ alt=‘Delete’ title=‘Delete’ > , when moving to next page and come back to the first page Trash icon appear and the text disappear !!!

see photo 1 and photo 2

more details :
i am not using a grid
i am using a master form with details form (orientation set to Editable grid view).
any idea how to fix this ?
thanks in advanced

1.png

2.png

I’ll have a look when I can as a form (editable grid view).

In the meantime I also would need to see the full code you have in the onRecord and on onScriptInit events - can you post them?

Plus also confirm the type for the field that will hold the “trash” icon?

Thanks

[QUOTE=adz1111;36104]I’ll have a look when I can as a form (editable grid view).

In the meantime I also would need to see the full code you have in the onRecord and on onScriptInit events - can you post them?

Plus also confirm the type for the field that will hold the “trash” icon?

Thanks[/QUOTE]

onScriptInit event

$sqlq = "SELECT COUNT(*) FROM treatment_history WHERE treatment_id = [t]";        

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;

OnLoadRecord event

[rec_pos] += 1;

if ( [rec_pos] == [last_record] ) {		// if last record only
	{delete} = "<img src='../_lib/img/delete_16.png' alt='Delete' title='Delete' >";   
} else {
	{delete} = '';
}

{delete} field type:HTML image

Regards

walid

Also - why have the detail as editable view? Your picture does not show the whole row. If you are looking to NOT allow deletion except on the last row (and presumably disallow editing too on only the last row), then using editable view provides you with way more features than you need - meaning you have to unpick it all. Why not use just a plain grid as your detail, and then set it as per my post?

EDIT: Re the issue with the HTML text displaying and not the image - that is a known bug right now with HTML Image field types in forms - they work correctly in Grids now though.

Thank you for looking at this.
i will do it like your advice

regards