Jump to content

UniStringGrid Cell editor


bolossis

Recommended Posts

Hi, is it possible to have an UniStringGrid  cell editor?

I try the hidden panel but this works only for UniDBGrid.

 

I have some Boolean values on a Stringgrid and want to have a checkbox inside the cells.

 

Any solution?

I check out the demos but found only solution for DBGrid.

 

 

Link to comment
Share on other sites

Hi Delphi Develeoper, you dont need a test case here,

its just a stringgrid with example 20 columns and 10 rows, one Fixed Cold and one Fixed Row and in the rest of the cells they should be a check box or a combobox where user can select false or true.

 

 test.jpg

0 = False

1 = True

 

Except of using zero and one, i would insert a check box or combobox (items=True,False)

Link to comment
Share on other sites

Hi,

 

Can you try to use this approach for now ?!

 

For example:

 

1. UniStringGrid1 -> ClientEvents -> UniEvents -> function beforeInit:

function beforeInit(sender, config)
{
    var me=sender;
    
    me._check=function(v, r, c){
        ajaxRequest(me, '_check', ['value='+v, 'rowIndex='+r, 'columnIndex='+(c+me.fxCols)]);
    }
}

2. UniStringGrid1 -> ClientEvents -> ExtEvents -> function reconfigure:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    for (i = sender.fxCols; i < columns.length; i++) {
        columns[i].rdonly=true;
        columns[i].align = 'center';
        columns[i].renderer = function(value, a) {
            return "<input type='checkbox'" + ((value == '1') ? "checked='checked'" : "") + " onclick='"+sender.nm+"._check(+this.checked, "+a.rowIndex+", "+a.columnIndex+")'>";
        };
    }
    
}

3. UniStringGrid1 -> OnAjaxEvent:

procedure TMainForm.UniStringGrid1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  if EventName='_check' then
    (Sender as TUniStringGrid).Cells[StrToInt(Params.Values['columnIndex']), StrToInt(Params.Values['rowIndex'])] := Params.Values['value']

end;

Result:

post-906-0-35543400-1514007260_thumb.png

 

Best regards,

  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi, i try to add and remove the events on runtime, is it possible?

If yes what do i wrong? it dows not work

procedure TRatesManagerForm.UniRadioButton9Click(Sender: TObject);
begin
  MyGrid.ClientEvents.ExtEvents.Clear;
  MyGrid.ClientEvents.UniEvents.Clear;

  RestGrid.ClientEvents.ExtEvents.Values['beforeInit'] :=
    'function (sender, config) ' +
    '{ ' +
    ' var me=sender; ' +
    '  me._check=function(v, r, c){ ' +
    '      ajaxRequest(me, ''_check'', [''value=''+v, ''rowIndex=''+r, ''columnIndex=''+(c+me.fxCols)]); ' +
    '    } ' +
    '} ';

  MyGrid.ClientEvents.UniEvents.Values['reconfigure'] :=
    'function (sender, store, columns, oldStore, oldColumns, eOpts) ' +
    '{ ' +
    '    for (i = sender.fxCols; i < columns.length; i++) { ' +
    '        columns[i].rdonly=true; ' +
    '        columns[i].align = ''center''; ' +
    '        columns[i].renderer = function(value, a) { ' +
    '            return "<input type=''checkbox''" + ((value == ''1'') ? "checked=''checked''" : "") + " onclick=''"+sender.nm+"._check(+this.checked, "+a.rowIndex+", "+a.columnIndex+")''>"; ' +
    '        }; ' +
    '    } ' +
    '} ';
end;
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...