Jump to content

how to clear a specific cell in uniDBGrid?


boka

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

image.png.e3d76eba4ca4e94f85dd2ca28bbf39a3.png

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

Link to comment
Share on other sites

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?


image.png.fd1fd366b117ff840029a4c6663db447.png

I just want to see/make the empty cell 'Остаток min' immediately right after changing 'Min-Max' selected above onto 'по среднему' (there are only two values)

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
            })
        }
    })
}

 

Link to comment
Share on other sites

Yep, much closer, thanx @Sherzod

Changed code a bit but on the repeat attempt it keeps the last used Cell in an edit state.

image.png.eb0afaab79a6f405771f0e1068cff890.png

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)
      })
    }
  })
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...