Jump to content

search on treemenu


IdrisZZ

Recommended Posts

  • 7 months later...
41 minutes ago, Luciano França said:


hello i need some solution

Grateful.

 

Solution

procedure TMainForm.Ed_BuscaChange(Sender: TObject);
var I, tamanho: Integer;
 no: TUniTreeNode;
 TextoNode: String;
begin
 tamanho := Length(Ed_Busca.Text);

 if tamanho > 0 then
  for I := 0 to UniTreeMenu1.Items.Count - 1 do Begin

   TextoNode := AnsiUpperCase(UniTreeMenu1.Items[I].Text);

   if Pos(AnsiUpperCase(Ed_Busca.Text), TextoNode) > 0 Then Begin
    no := UniTreeMenu1.Items[I];

    UniTreeMenu1.Selected := no;

    Break;
   end;

  End;

 if Trim(Ed_Busca.Text) = EmptyStr Then
  UniTreeMenu1.JSInterface.JSCall('rootItem.getNode().collapseChildren', [True]);

end;

 

Link to comment
Share on other sites

  • 3 weeks later...
On 5/23/2023 at 4:31 AM, Luciano França said:

Solution

procedure TMainForm.Ed_BuscaChange(Sender: TObject);
var I, tamanho: Integer;
 no: TUniTreeNode;
 TextoNode: String;
begin
 tamanho := Length(Ed_Busca.Text);

 if tamanho > 0 then
  for I := 0 to UniTreeMenu1.Items.Count - 1 do Begin

   TextoNode := AnsiUpperCase(UniTreeMenu1.Items[I].Text);

   if Pos(AnsiUpperCase(Ed_Busca.Text), TextoNode) > 0 Then Begin
    no := UniTreeMenu1.Items[I];

    UniTreeMenu1.Selected := no;

    Break;
   end;

  End;

 if Trim(Ed_Busca.Text) = EmptyStr Then
  UniTreeMenu1.JSInterface.JSCall('rootItem.getNode().collapseChildren', [True]);

end;

 

but the other items are not lost or hidden.
Thank You

image.png.6444ffebe671f3b5c0bf90dfa2965969.png

Link to comment
Share on other sites

On 6/11/2023 at 9:13 AM, Muhammad Idris said:

but the other items are not lost or hidden.
Thank You

image.png.6444ffebe671f3b5c0bf90dfa2965969.png

 

procedure TForm_BuscaMainMenuHost.Ed_BuscaChange(Sender: TObject);
var I, tamanho: Integer;
 TextoNode: String;
 Achou: Boolean;
begin
 Achou := false;
 tamanho := Length(Ed_Busca.Text);

 if tamanho >= 4 then
  for I := 0 to DBTreeList.Items.Count - 1 do Begin

   TextoNode := AnsiUpperCase(DBTreeList.Items[I].Text);

   if Pos(AnsiUpperCase(Ed_Busca.Text), TextoNode) > 0 Then Begin

    DBTreeList.Selected := DBTreeList.Items[I];

    DBTreeList.Selected.Expand(false);
    Achou := True;

    Break;
   end;

  End;

 if (trim(Ed_Busca.Text) = EmptyStr) Or (Not Achou) Then
  DBTreeList.JSInterface.JSCall('rootItem.getNode().collapseChildren', [True]); 

end;

 

Link to comment
Share on other sites

12 hours ago, Luciano França said:

 

procedure TForm_BuscaMainMenuHost.Ed_BuscaChange(Sender: TObject);
var I, tamanho: Integer;
 TextoNode: String;
 Achou: Boolean;
begin
 Achou := false;
 tamanho := Length(Ed_Busca.Text);

 if tamanho >= 4 then
  for I := 0 to DBTreeList.Items.Count - 1 do Begin

   TextoNode := AnsiUpperCase(DBTreeList.Items[I].Text);

   if Pos(AnsiUpperCase(Ed_Busca.Text), TextoNode) > 0 Then Begin

    DBTreeList.Selected := DBTreeList.Items[I];

    DBTreeList.Selected.Expand(false);
    Achou := True;

    Break;
   end;

  End;

 if (trim(Ed_Busca.Text) = EmptyStr) Or (Not Achou) Then
  DBTreeList.JSInterface.JSCall('rootItem.getNode().collapseChildren', [True]); 

end;

 

I mean, for example, if you type Labora, the other items will automatically disappear because there are many items in the treemenu.
Thank You

Treemenu_Search_1.zip

Link to comment
Share on other sites

I advise the colleague to change his approach

It would be better to have a TClientDataset to be able to do a more elaborate search and link to a "TUniDbTreeGrid" and you could put some CSS to make it look like "TUniTreeMenu"

I have it here and it works perfectly for Accounting Plan

For my Main menu I did a simple search but as my system has few items there is no problem with the search I put the code for.

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