Jump to content

grid column editor in run time


jahlxx

Recommended Posts

  • 2 months later...

Hi,
 
Maybe this will help you to do;

procedure BaseGridAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
var colIndex : Integer;
begin
  inherited;

  if EventName = 'select' then begin
    colIndex := BaseGrid.ColumnByName('FieldValue').Index;
    case TFieldType of
      ftDateTime :
        begin
          UniSession.AddJS(BaseGrid.JSName + '.columnManager.columns[' + IntToStr(colIndex) + '].setEditor(' +
                           ' new Ext.form.field.Date({' +
                           ' id: ''' + BaseGrid.JSName + 'columnsEditor' + IntToStr(colIndex) + ''', ' +
                           ' xtype: ''datefield'',' +
                           ' format: ''d.m.Y'',' +
                           ' anchor: ''100%'',' +
                           ' })' +
                           ' );');
        end;
      ftInteger :
        begin
          UniSession.AddJS(BaseGrid.JSName + '.columnManager.columns[' + IntToStr(colIndex) + '].setEditor(' +
                           ' new Ext.form.field.Number({' +
                           ' id: ''' + BaseGrid.JSName + 'columnsEditor' + IntToStr(colIndex) + ''', ' +
                           ' xtype: ''numberfield'',' +
                           ' anchor: ''100%'',' +
                           ' })' +
                           ' );');
        end;
      else
        begin
          UniSession.AddJS(BaseGrid.JSName + '.columnManager.columns[' + IntToStr(colIndex) + '].setEditor(' +
                           ' new Ext.form.field.Text({' +
                           ' id: ''' + BaseGrid.JSName + 'columnsEditor' + IntToStr(colIndex) + ''', ' +
                           ' xtype: ''textfield'',' +
                           ' anchor: ''100%'',' +
                           ' })' +
                           ' );');
        end;
    end;
  end;
end;
Link to comment
Share on other sites

you can't use beforeEdit event, i am not sure why but grid cancel editing automatically.

 

And i can create a checkbox on runtime, it says "checkbox is not a constructor" etc. still working on it.

 

if anyone can find a better solution for this please let us know, this is very critical issue for most developers i think.

Link to comment
Share on other sites

  • 4 years later...

Hi!

@Sherzod  How can I prevent dbgrid editors Tcontrol (unicombobox) from being automatically deleted after change editor on runtime?

If I create control like showed above in ttamturk's post everithing works fine, but after change the editor the combobox will be removed/deleted/freed (second time I can't use it, I need to create again) 

I could need a different editor in every row depend on the data type. 

Combobox could contains hundred of items, so I think is not too good to create and release every time users clicks on it. 

 

thanks

Link to comment
Share on other sites

24 minutes ago, csaszko said:

How can I prevent dbgrid editors Tcontrol (unicombobox) from being automatically deleted after change editor on runtime?

If I create control like showed above in ttamturk's post everithing works fine, but after change the editor the combobox will be removed/deleted/freed (second time I can't use it, I need to create again) 

I could need a different editor in every row depend on the data type. 

Combobox could contains hundred of items, so I think is not too good to create and release every time users clicks on it. 

Hello,

I'm sorry, your case is not very clear to me.

Link to comment
Share on other sites

1 hour ago, Sherzod said:

Hello,

I'm sorry, your case is not very clear to me.

I will try to say explain other way.

I have tables something like this

id, t2.field_name, t1.field_value, t1. field_type... etc 

in dbgrid 

col0=field_name, column1=field_value (something like propertygrid but more columns)

column1 could contains different type of data so i need different kind of editor (date, text, combo) 

if I scroll/change row I need to show the specific editor for the actual row (not column). 

I can create editors runtime, but if user navigate an another row which has a different kind of data, it will change the editor and the previous editor control won't be availabe again, I can't reach that combobox anymore. (Cannot read properties of null) 

with date and free text, there is no problem, but with combobox with a lot of items... so is not good create each time when user want to edit that record. 

 

 

 

 

 

Link to comment
Share on other sites

2 hours ago, Sherzod said:

Hello,

I'm sorry, your case is not very clear to me.

I need something like in verticaltreegrid, in each row could be a different editor. Unfortunately verticalgrid is not working form me neither, because of I use the same field for different type, and not different field.  

 

Link to comment
Share on other sites

1 hour ago, Sherzod said:

Have you tried searching the forum for solutions?

Yes of course (you can check my forum history) , and demo, and source code and google.. and tried different comp.

found this in unidbgrid.pas: 

// we must destroy picker each time column is reconfigured. Ext JS issue. Check again in 6.5  

ok this is for datetimepicker.. not combobox , but at some point destroying as well

 

Any idea, or did you find a forum solution what I could not? 

 

Link to comment
Share on other sites

23 minutes ago, Sherzod said:

You can also try searching with the keyword "seteditor".

I have read every post in this forum about that. I have been searching for two days, so please help me.

I have hidden panel where I put combobox. On runtime I fill these combobox with desired items. I use this code:

 

case 0:works one times, case 1: works fine.  

UniDBGrid1AjaxEvent:

if EventName = 'select' then
  begin
    colIndex := 1;
    Case IndexText(fajl_extra_infok_ZQuery.FieldByName('extra_inf_tipus')
      .AsString, ['combo', 'datum']) of
      0:
        begin

         
            with UniDBGrid1 do
              JSInterface.JSCall('setEditor', [UniComboBox1.JSControl],
                ColumnByName('extra_inf_ertek').JSColumn);

           
        end;
      1:
        begin
         
          UniSession.AddJS(UniDBGrid1.JSName + '.columnManager.columns[' +
            IntToStr(colIndex) + '].setEditor(' + ' new Ext.form.field.Date({' +
            ' id: ''' + UniDBGrid1.JSName + 'columnsEditor' + IntToStr(colIndex)
            + ''', ' + ' xtype: ''datefield'',' + ' format: ''d.m.Y'',' +
            ' anchor: ''100%'',' + ' })' + ' );');
        end;

      
    else
      begin
        UniSession.AddJS(UniDBGrid1.JSName + '.columnManager.columns[' +
          IntToStr(colIndex) + '].setEditor(' + ' new Ext.form.field.Text({' +
          ' id: ''' + UniDBGrid1.JSName + 'columnsEditor' + IntToStr(colIndex) +
          ''', ' + ' xtype: ''textfield'',' + ' anchor: ''100%'',' +
          ' })' + ' );');
      end;
    end;
  end;

 

 

Link to comment
Share on other sites

Of course we will try to help you.
But to be clear...

6 hours ago, csaszko said:

column1 could contains different type of data so i need different kind of editor (date, text, combo) 

How you define is not very clear.

6 hours ago, csaszko said:

if I scroll/change row I need to show the specific editor for the actual row (not column). 

6 hours ago, csaszko said:

I can create editors runtime, but if user navigate an another row which has a different kind of data, it will change the editor and the previous editor control won't be availabe again, I can't reach that combobox anymore. (Cannot read properties of null) 

It's also not clear.

6 hours ago, csaszko said:

with date and free text, there is no problem, but with combobox with a lot of items... so is not good create each time when user want to edit that record. 

?

Can you create a simple example with few records to understand your case?

Link to comment
Share on other sites

On 3/31/2022 at 7:45 PM, Sherzod said:

Of course we will try to help you.
But to be clear...

How you define is not very clear.

It's also not clear.

?

Can you create a simple example with few records to understand your case?

Would you check please?

Link to comment
Share on other sites

On 4/1/2022 at 1:11 AM, csaszko said:

try to edit variable_value column more than one record. 

Hello,

Sorry, I haven’t been able to implement it yet, and I think it can’t be implemented right now, especially for some types (date, time).

Link to comment
Share on other sites

9 minutes ago, Sherzod said:

Hello,

Sorry, I haven’t been able to implement it yet, and I think it can’t be implemented right now, especially for some types (date, time).

Hi, 

Sorry for hear that. OK. I will find other way then. 

Tanks

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