Jump to content

combox with multiple selection by checkbox


Nicola Nicoletti

Recommended Posts

  • 1 month later...
On 8/5/2020 at 8:13 AM, Hayri ASLAN said:

Hi, 

Please specify an edition and build of UniGUI you are using. 

Hello, i'm using the build 1534.

I found the component but the only way i found to get the data was trough the remote query but remote query is no the solution that i need. I need the possibility to link a datasource to the combobox.

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Eu usei uma lista de caixas de seleção muito antes de o componente existir,
isso é muito fácil de criar.
você apenas cria dinamicamente componentes tunicheckbox em um tuniscrollbox

e associar o evento click a uma função que tornará o salvamento do registro muito simples de fazer.

 

//sample
 // sbox ->tuniscrollbox
  while not qry.eof do
    Begin
      cb         :=TUniCheckBox.Create(sbox);
      cb.parent  :=sbox;
      cb.caption :=formatfloat('000',qryid.Value)+'-'+qryDescription.value;
      cb.AlignWithMargins :=true;
      cb.Align   :=alTop;
      cb.onclick :=clickcheck;
      qry.Next;
    End;

procedure tform.clickcheck(sender:tobject);
var i:integer;
begin
for I := 0 to sbox.ComponentCount-1 do
   begin
      if tunicheckbox(sbox.Components).Checked then
          //execute update
   end;

end;
 

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

unimSelect can be used in multiselect mode

http://forums.unigui.com/index.php?/topic/15111-мультивыбор-для-touch-extmodern/&do=findComment&comment=82696

 

selPrm - TunimSelect
  
procedure TfmmParentEditObject.FillPrm;
begin
  dmm.qPrm.Open;
  dmm.qPrm.First;

  while not dmm.qPrm.Eof do
  begin
    //selTypes.Items.AddObject(qTypesNAME.Value, Pointer(qTypesID.Value));

    selPrm.JSInterface.JSCode(#1'.getStore().add({id: "' + dmm.qPrmID.AsString + '", val: "' + dmm.qPrmNAME.Value + '"});');
    dmm.qPrm.Next;
  end;

  dmm.qPrm.Close;
end;

function TfmmParentEditObject.SetPrmSelectedValues(const Val: string): string;
Var
 sl: TStringList;
 i: integer;
 s: string;
begin
// на входе значения через запятую: 3,5,8,

  if Val.IsEmpty then
    exit;

  sl := TStringList.Create;
  try
    sl.CommaText := Val;

    for I := 0 to pred(sl.Count) do
    begin
      if not sl[i].IsEmpty then
      begin
        if s.IsEmpty then
          s := '"' + sl[i] + '"'
        else
          s := s + ',"' + sl[i] + '"';

      end;// if


    end;// for

    if not s.IsEmpty then
      result := #1'.setValue([' + s + ']);';
  finally
    FreeAndNil(sl);
  end;
end;

procedure TfmmParentEditObject.InitPrm;
begin
  FillPrm;
  selPrm.JSInterface.JSConfig('multiSelect', [True]);
  selPrm.JSInterface.JSConfig('valueField', ['id']);// key field

  selPrm.JSInterface.JSAddListener('painted', 'function(me){if (me.getValue()) {me.setPlaceholder()} else {me.setPlaceholder(me._placeHolder)}}');
  selPrm.JSInterface.JSAddListener('change', 'function(me){if (me.getValue()) {me.setPlaceholder()} else {me.setPlaceholder(me._placeHolder)} ajaxRequest('+ Self.WebForm.JSName +', "selEvents", ["objName="+me.uname, "values="+me.getValue(), "selIds="+me.getSelIds(me)])}');

  selPrm.ClientEvents.UniEvents.Values['afterCreate'] :=

    'function afterCreate(sender) ' +
    '{' +
    '  var done = new Ext.Button({' +
    '        text: ''OK'',' +
    '        renderTo: sender.getPicker(),' +
    '        style: ''position: absolute; bottom: 0px; width: 100%; background-color: gray;''' +
    '    });' +
    '   sender.getSelIds = function(sender) {' +
    '        let Ids = "";' +
    '        if (sender.getSelection() == null) return "";' +
    '        sender.getSelection().forEach(function(item) {' +
    '            Ids += item.id + ","' +
    '        });' +
    '        return Ids.slice(0, -1);' +
    '    };' +
    '    createToolTip(sender, ' + QuotedStr(StrToJS(constPrm)) + '); ' +
    '}';
end;

procedure TfmmParentEditObject.UnimFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
begin
  inherited;
  if EventName = 'selEvents' then
  begin
    // список ID типов через запятую
    if FindComponent(Params.Values['objName']) = selPrm then
      sPrmList := Params.Values['selIds'];// см. InitPrm

  end;
end;

 

Screenshot_5.jpg

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