11-24-2020, 10:02 AM
Hi Alexandre,
Not sure... I think it's situation 2. I'll let my code tell the situation.
Not sure... I think it's situation 2. I'll let my code tell the situation.
Code:
procedure TDlgAfboekingen.RegisterCallbacks;
begin
inherited;
WebApplication.RegisterCallBack('DeleteRestantCallback', DeleteRestantCallback);
end;
// 1. Called after user clicks [delete] button in bootstrap grid row
procedure TDlgAfboekingen.dbGridCustomAsyncEvents1AsyncEvent(Sender: TObject; EventParams: TStringList);
var
PerceelIndex: string;
begin
// add tag as callback data
PerceelIndex := EventParams.Values['row'];
// <snip> some processing based on PerceelIndex
// here I store information that will be retrieved from DeleteRestantCallback()
// CallbackData is a property of TDlgAfboekingen. I would prefer to pass this information
// to DeleteRestantCallback by using event parameters similar to DeleteRestantCallback?PerceelIndex=1
CallbackData.AddPair('PerceelIndex', PerceelIndex);
// show question. result will be handled by callback asynchronous
WebApplication.ShowConfirm(
_('Some question?'),
'DeleteRestantCallback',
'',
_('Yes'),
_('No'));
end;
// 2. Called after user closes confirmation dialog
procedure TDlgAfboekingen.DeleteRestantCallback(EventParams: TStringList);
var
PerceelIndex: integer;
Perceel: TPerceel;
OK: boolean;
js: string;
begin
// Confirm callback has 1 main parameters:
// RetValue (Boolean), indicates if the first button (Yes/OK/custom) was choosen
OK := SameText(EventParams.Values['RetValue'], 'True');
if OK
then begin
PerceelIndex := StrToIntDef(CallbackData.Values['PerceelIndex'], -1);
// <snip> process detele action
// refresh table on webpage
js := '$(''#DBGRID'').bootstrapTable(''refresh'', {silent: true});';
WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(js);
end;
// remove all callback data
CallbackData.Clear;
end;