boka Posted January 19, 2023 Share Posted January 19, 2023 I have a lookup db field among different others in my connected TxxQuery and I want to clear some of them on DBGrid right after choosing the value from dropdown, when it is already collapsed. Assigning nulls on "data" level doesn't work IsMinMax := SameText(qDemandSettingsMETHOD_TYPE.Value, 'MM'); if IsMinMax then qDemandSettingsLOOKUP_DEPTH.AsVariant := null else qDemandSettingsLEFTOVER_MIN.AsVariant := null; [METHOD_TYPE is that "lookup" field, LOOKUP_DEPTH and LEFTOVER_MIN - those I need to clear in DBGrid] Do I need to do something on client side or somehow force to refresh the grid? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 19, 2023 Share Posted January 19, 2023 5 minutes ago, boka said: I have a lookup db field among different others in my connected TxxQuery and I want to clear some of them on DBGrid right after choosing the value from dropdown, when it is already collapsed. Hello, Can you please explain in more detail? Quote Link to comment Share on other sites More sharing options...
boka Posted January 19, 2023 Author Share Posted January 19, 2023 When choosing first value 'по среднему' from dropdown list I want to clear value from cell 'Остаток min' in that row, when choosing 'Min-Max' - from 'Глубина анализа'. Just to see them empty. As it seen in my example I do it with the data of corresponding dataset fields (in OnChange event of underlying 'dropdown' TField) but that doesn't lead to the DBGrid representation Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 19, 2023 Share Posted January 19, 2023 These fields are calculated fields? Quote Link to comment Share on other sites More sharing options...
boka Posted January 19, 2023 Author Share Posted January 19, 2023 12 minutes ago, Sherzod said: These fields are calculated fields? nope, plain data fields. I execute that code from a DataModule if it matters 'cause haven't found how to catch the dropdown closing event from a Form Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 19, 2023 Share Posted January 19, 2023 procedure TMainForm.UniDBGrid1SetCellValue(Sender: TObject; ACol, ARow: Integer; AField: TField; var Value: Variant); begin // end; ? Quote Link to comment Share on other sites More sharing options...
boka Posted January 23, 2023 Author Share Posted January 23, 2023 As far as I understand this event fires when the AField changes. Ok, now I hook the changes of that dropdown field in OnSetCellValue on Form (Previously was in OnChange event in DataModule). But in OnSetCellValue the underlying DataSet is in dsBrowse state that makes me turn it into Edit state first, then change the necessary fields values and Post them after all because only after DataSet.Post I see the refreshed data in DBGrid. And is there any way to refresh the DBGrid/Row/Cell representation without posting? I just want to see/make the empty cell 'Остаток min' immediately right after changing 'Min-Max' selected above onto 'по среднему' (there are only two values) Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 23, 2023 Share Posted January 23, 2023 Hello @boka You can try something like this I think. 1. UniDBGrid1.ClientEvents.ExtEvents -> function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) { columns.forEach(function(col) { if (col.getEditor().xtype == "combo") { col.getEditor().on('select', function(combo) { Ext.defer(function() { combo.ownerCt.completeEdit(); ajaxRequest(sender, 'comboSelected', {}) }, 100) }) } }) } 2. UniDBGrid1->OnAjaxEvent -> procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'comboSelected' then begin with (Sender as TUniDBGrid).DataSource.DataSet do begin Edit; if FieldByName('LookupField').Value = ... then begin FieldByName('YourField1').Value := ... end else begin FieldByName('YourField2').Value := ... end; Post; end; end; end; Quote Link to comment Share on other sites More sharing options...
boka Posted January 25, 2023 Author Share Posted January 25, 2023 Thanks, @Sherzod Ok, now I catch that fired AJAXEvent and get those necessary cells clear before Post already! But! The combobox (without Post) turns back to the initial value every time! And even though it was already in changed state! if EventName = 'comboSelected' then begin var DS := (Sender as TUniDBGrid).DataSource.DataSet; if not (DS.State in dsEditModes) then DS.Edit; if DS.FieldByName('METHOD_NAME').Value = 'Min-Max' then begin DS.FieldByName('LOOKUP_DEPTH').Value := null; DS.FieldByName('METHOD_TYPE').Value := 'MM'; DS.FieldByName('METHOD_NAME').Value := 'Min-Max' end else begin DS.FieldByName('LEFTOVER_MIN').Value := null; DS.FieldByName('METHOD_TYPE').Value := 'AV'; DS.FieldByName('METHOD_NAME').Value := 'по среднему'; end; // Post; end; As you see I even tried to reassign it's value. P.S. I don't want to Post changes without need. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 25, 2023 Share Posted January 25, 2023 Hello @boka Okay. Can you make a simple testcase? I will try on your test case. Quote Link to comment Share on other sites More sharing options...
boka Posted January 26, 2023 Author Share Posted January 26, 2023 voila! lookup_demo.zip Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 26, 2023 Share Posted January 26, 2023 19 hours ago, boka said: I don't want to Post changes without need. When and how will you use POST? Quote Link to comment Share on other sites More sharing options...
boka Posted January 26, 2023 Author Share Posted January 26, 2023 Like in normal use - eihter when pressing corresponding Navigator button or it posts automatically when changing a row. I don't want to change common user/UI behavior. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 27, 2023 Share Posted January 27, 2023 18 hours ago, boka said: Like in normal use - eihter when pressing corresponding Navigator button or it posts automatically when changing a row. I don't want to change common user/UI behavior. Dirty workaround (for a special case). procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin // if EventName = 'comboSelected' then begin // var DS := (Sender as TUniDBGrid).DataSource.DataSet; // if DS.State in dsEditmodes then // DS.Edit; // // if DS.FieldByName('LU').Value = 'Min-Max' then begin // DS.FieldByName('VAL1').Value := null; // DS.FieldByName('VAL2').Value := null; // end // else begin // DS.FieldByName('VAL3').Value := null; // end; // //// DS.Post; // end; end; function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) { columns.forEach(function(col) { if (col.getEditor().xtype == "combo") { col.getEditor().on('select', function(combo) { Ext.defer(function() { //dataIndex = 1 if (col.dataIndex === '1' && combo.getValue() === 'Min-Max') { var _row = sender.getStore().indexOf(sender.getSelection()[0]); //columnIndx = 2 var _colIndx = 2; sender.editingPlugin.startEditByPosition({ row: _row, column: _colIndx }); sender.getColumns()[_colIndx].getEditor().setValue(null); //columnIndx = 3 _colIndx = 3; sender.editingPlugin.startEditByPosition({ row: _row, column: _colIndx }); sender.getColumns()[_colIndx].getEditor().setValue(null); } else if (col.dataIndex === '1' && combo.getValue() != 'Min-Max') { //columnIndx = 4 _colIndx = 4; sender.editingPlugin.startEditByPosition({ row: _row, column: _colIndx }); sender.getColumns()[_colIndx].getEditor().setValue(null); } }, 0) }) } }) } Quote Link to comment Share on other sites More sharing options...
boka Posted January 27, 2023 Author Share Posted January 27, 2023 Yep, much closer, thanx @Sherzod Changed code a bit but on the repeat attempt it keeps the last used Cell in an edit state. I tried both methods to finish editing but did not succeed. function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) { columns.forEach(function(col) { if (col.getEditor().xtype == "combo") { col.getEditor().on('select', function(combo) { Ext.defer(function() { var _row = sender.getStore().indexOf(sender.getSelection()[0]); if (col.dataIndex === '1' && combo.getValue() === 'Min-Max') { var _colIndx = 2; sender.editingPlugin.startEditByPosition({ row: _row, column: _colIndx }); sender.getColumns()[_colIndx].getEditor().setValue(null); sender.editingPlugin.completeEdit; //1st _colIndx = 3; sender.editingPlugin.startEditByPosition({ row: _row, column: _colIndx }); sender.getColumns()[_colIndx].getEditor().setValue(null); sender.editingPlugin.completeEdit; } else if (col.dataIndex === '1' && combo.getValue() != 'Min-Max') { var _colIndx = 4; sender.editingPlugin.startEditByPosition({ row: _row, column: _colIndx }); sender.getColumns()[_colIndx].getEditor().setValue(null); sender.editingPlugin.editing = false; // 2nd } }, 0) }) } }) } Quote Link to comment Share on other sites More sharing options...
boka Posted January 30, 2023 Author Share Posted January 30, 2023 DBG.RefreshCurrentRow solves the problem w/o JS and catching grid events. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.