Jump to content

Grid Field Editor(combobox NOT DBComboBox): validateedit - LookUp additional Row Data


andyhill

Recommended Posts

I have a need where the user can select from a grid's editor combobox an item of interest and then using the 'validateedit' event I fetch and populate the other specific row cell data relating to the selection = live update of SellPrice.

The reason why it is not a DBComboBox is the fact that the user is also allowed to type in an item manually even if it does not exist in the combobox list.

So if it exists, then SellPrice etc. is automatically updated in the grid, if not exist then user can type in the SellPrice manually.

My code works to a point, but fails to advance to the next cell forcing a repaint, only by mouse clicking the next cell (or TAB Key) does the SellPrice display - our focus is stuck within the editors combobox no matter what we do in code - please advise.

procedure TMainForm.grdWorkSheetAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);

...

col:= grdWorkSheet.CurrCol; // 1=Quantity, 2=Description, 3=SellPrice
if col = 2 then begin

  UniMainModule.PreItemDescription:=  Trim(Params.Values['old']);
  UniMainModule.PostItemDescription:= Trim(Params.Values['new']);

  if ( (UpperCase(UniMainModule.PreItemDescription) <> UpperCase(UniMainModule.PostItemDescription))
  and  (UniMainModule.PostItemDescription <> '')
     ) then begin

    if UniMainModule.tblLkUpItems.Locate('Description', VarArrayOf([Trim(UniMainModule.PostItemDescription)]), [loCaseInsensitive]) = True then begin
      grdWorkSheet.Columns[2].Field.AsString:= UniMainModule.PostItemDescription;
      grdWorkSheet.Columns[3].Field.AsFloat:=  UniMainModule.tblLkUpItems.FieldByName('SellPrice').AsFloat;
      grdWorkSheet.Columns[4].Field.AsString:= UniMainModule.tblLkUpItems.FieldByName('BASType').AsString;
      grdWorkSheet.CurrCol:= grdWorkSheet.CurrCol + 1;
      grdWorkSheet.Repaint;
      ValidateBusyFlag:= False;
...

 

 

 

Link to comment
Share on other sites

Editor closes and remains focused - no amount of code can shift focus to next cell (thus painting new values) - Trying all sorts of tricks - not working :(

grdWorkSheet.Columns[2].Editor.Perform(CM_DialogKey, VK_TAB, 0);

After Field values adjusted in code I need to move focus to next column.

Link to comment
Share on other sites

12 minutes ago, andyhill said:

I sent shell project to you privately the other day.

Yes, I saw.

But forgive me for my misunderstanding.

It is also inconvenient to require clarification from you.

Can you create a gif file or video where we can see the issue?

Or also, what do you expect works on VCL? Can you make a simple testcase on VCL to check the difference? 

Link to comment
Share on other sites

Sorry, it's difficult for me to understand your code completely.

But maybe I solved your issue, check please.

It's possible your assigned events may conflict, I haven't looked.

 

procedure TMainForm.UniFormCreate(Sender: TObject);
var
  MyScript: String;
  i: Integer;
begin
  UniDBGrid1.JSInterface.JSAddListener('reconfigure',
    'function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)'+
    '{                                                                        '+
    '    columns.forEach(function(col){                                       '+
    '        var ed=col.getEditor();                                          '+
    '        if (ed.xtype === "combo"){                                       '+
    '              ed.addListener("select",                                   '+
    '                        function (combo, record) {                       '+
    '                            var _cRow = sender.getSelectionModel().getCurrentPosition().row;         '+
    '                            var _cCol = sender.getSelectionModel().getCurrentPosition().column;      '+
    '                            _cCol+=1;                                                                '+
    '                            /* You must take into account the count of hidden columns */             '+
    '                            _cCol-=1;                                                                '+
    '                            Ext.defer(function(){sender.editingPlugin.completeEdit()}, 10);          '+
    '                            Ext.defer(function(){sender.editingPlugin.startEdit(_cRow, _cCol)}, 20); '+
    '                        }                                                                            '+
    '              )                                                                                      '+
    '        }                                                                                            '+
    '    })                                                                                               '+
    '}                                                                                                    '
  );
  //////////////////////////////////////////////////////////////////////////////
...

 

Link to comment
Share on other sites

Fantastic - Thank You Sherzod.

Is it possible to do this in the Grid's 'validateevent' after verifying it was the CombBox that triggered the 'validateedit' Event:-

MyJSName:= MainForm.grdWorkSheet.JSName;
UniSession.AddJS('Ext.defer(function(){'+MyJSName+'.editingPlugin.completeEdit()}, 10);');

I tried this but it had no effect ?
 

Link to comment
Share on other sites

As I said before, the reconfigure above works great.

I asked why can't I do this inside the Grid's "validateedit' Event instead ?

UniSession.AddJS('Ext.defer(function(){'+MyJSName+'.editingPlugin.completeEdit()}, 10);');

Link to comment
Share on other sites

41 minutes ago, andyhill said:

As I said before, the reconfigure above works great.

I know it works, that's not what I'm asking.

42 minutes ago, andyhill said:

I asked why can't I do this inside the Grid's "validateedit' Event instead ?

UniSession.AddJS('Ext.defer(function(){'+MyJSName+'.editingPlugin.completeEdit()}, 10);');

 

2 hours ago, Sherzod said:
On 1/19/2024 at 1:37 AM, andyhill said:

I tried this but it had no effect ?

How did you try? What code are you using for this?

 

Link to comment
Share on other sites

Using Grid.Ext.Events 'validateedit'

'validateedit' Event checks to see if the CurrCol is using a ComboBox editor, if so the Event processes the ComboBox's before and after values

A Logic decision is made in code, if required then automatically populating other Grid Cells (on the same row) with new data relating to the new ComboBox value

ComboBox Editing is closed <------- this is what your 'reconfigure' Event does now

Grid moves on to next cell

ALL THIS WORKS USING THE 'reconfigure' Event you gave me earlier.

As A Teaching Lesson
My additional question was why can't I just use the code below inside the Grid's 'validateedit' Event:- 

UniSession.AddJS('Ext.defer(function(){'+GridJSName+'.editingPlugin.completeEdit()}, 10);');

instead of relying on the ComboBox's 'reconfigure' Event to close the editor ?

Is it a timing issue ?

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...