Search toolbar separated from the tree grid

 
Hello.

Is it possible to have a search bar not included in the tree grid? Something like this:
Also, could we define some subfilter like date picker?
Could you please provide me an example for this approach?

Best regards,
M





9 Replies 1 reply marked as answer

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 11, 2020 04:29 PM UTC

Hi Customer, 
 
Thanks for contacting Syncfusion Support. 
 
Query#:- Is it possible to have a search bar not included in the tree grid? could we define some subfilter like date picker? 
 
From your query we understood that you need to place external search Toolbar Item instead of using default Toolbar. To achieve this requirement we have placed the Toolbar component externally and rendered it as Search TextBox and DatePicker using template property of the Toolbar. Using Search and filterByColumn method we have performed the Search actions in TreeGrid. 

Refer to the code below:- 
App.Component.html   
<ejs-toolbar (created)="onCreate($event)">      
         <e-items> 
            <e-item template='<input type="text" tabindex="1" id="dpelement" />' type='Input' align='Left'> 
             </e-item> 
             <e-item template='<input type="text" tabindex="1" id="inputelement" />' type='Input' align='Right'> 
             </e-item> 
         </e-items> 
    </ejs-toolbar> 
   <ejs-treegrid #treegrid [dataSource]='data' height='350' allowPaging='true' [pageSettings]='pageSettings' 
              childMapping='subtasks' [treeColumnIndex]='1' allowFiltering='true'> 
            <e-columns> 
                <e-column field='taskID' headerText='Task ID' width='80' textAlign='Right'></e-column> 
                           .  .     . 
             </e-columns> 
   </ejs-treegrid> 
        
 
App.Component.ts 
 
           export class AppComponent { 
                  public searchInput: any = new TextBox({ 
                      placeholder: "Search", 
                      change: args => { 
                          this.treegrid.search(args.value);    //perform search action using Search method 
                      } 
                  }); 
                  public datePicker: any = new DatePicker({ 
                      placeholder: "Sub filter: Start Date", 
                      change: e => { 
                          this.treegrid.filterByColumn("startDate", "equal", e.value);   //using filterByColumn method perform Filtering on datePicker  
                      } 
                  }); 
                  public onCreate(e: any) { 
                      this.searchInput.appendTo("#inputelement"); 
                      this.datePicker.appendTo("#dpelement"); 
                  } 
              } 
 
 
Screenshot:- 
 
 
As Like DatePicker:-  
 
 
Refer to the documentation below:- 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Farveen sulthana T 


Marked as answer

MM MM December 11, 2020 05:23 PM UTC

Hello,

Thank you for a quick answer, it was just what I am looking for.
One more question: What about Combobox in the filter. let's say that I have an object like: 

[
      { id: 1name: 'Daily'},
      { id: 2name: 'Weekly' },
      { id: 3name: 'Monthly'}
    ]

And I want to search for the name because I have the name property in the list grid. Then filterByColumn is not working as expected or maybe I connected something wrong...
this.treegrid.filterByColumn("startDate", "equal", e.value);


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 14, 2020 02:44 PM UTC

 
Hi Customer, 
 
Query#:- What about Combobox in the filter. And I want to search for the name because I have the name property in the list grid.  

As we have mentioned earlier, you can also place the ComboBox using template property of the Toolbar component provided in the documentation. Also you can get the selected text using change event of the ComboBox and pass the text to filterByColumn method to get the filtered records in TreeGrid.  

Refer to the code below:- 

App.Component.html 
 
<ejs-toolbar (created)="onCreate($event)"> 
    <e-items> 
        <e-item template=' <input type="text" tabindex="1" id="comboelement"/>' type='Input' align='Left'> 
        </e-item> 
             .    .   . 
    </e-items> 
</ejs-toolbar> 
 
App.Component.ts 
 
export class AppComponent { 
  public data: Object[] = []; 
   
  public taskData: { [key: string]: Object }[] = [ 
    { Id: "1", TaskName: "Planning" }, 
    { Id: "2", TaskName: "Plan timeline" }, 
    { Id: "3", TaskName: "Design" } 
  ]; 
  public Combobox: any = new ComboBox({ 
    //set the data to dataSource property 
    dataSource: this.taskData, 
    change: args => { 
      var val = args.value; 
      if (!isNullOrUndefined(val)) { 
        this.treegrid.filterByColumn("taskName", "equal", val); 
      } else this.treegrid.clearFiltering(); 
    }, 
                       // use text and Value with name value 
    fields: { text: "TaskName", value: "TaskName" }, 
    // set placeholder to ComboBox input element 
    placeholder: "Select a task" 
  }); 
 
 
Screenshot:-  
 
Note:- To get name value in args of change event use text and value property of fields of combobox of TaskName. 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Farveen sulthana T 



MM MM December 14, 2020 04:07 PM UTC

Hello

I am not using HTML tag e-columns, could you please take a look at dynamic column loading - example? 
My guess is that I am not biding correctly the Combobox properties. Could you provide me an example for dynamic columns from the " example" and biding for the combobox filter - Priority?

   "@syncfusion/ej2-angular-treegrid""~17.3.27",
Angulr 7

<e-columns>
      <e-column field='taskID' headerText='Task ID' width='80' textAlign='Right'></e-column>
      <e-column field='taskName' headerText='Task Name' width='200'></e-column>
      <e-column field='startDate' headerText='Start Date' width='100' format="yMd" textAlign='Right'></e-column>
      <e-column field='duration' headerText='Duration' width='90' textAlign='Right'></e-column>
      <e-column field='progress' headerText='Progress' width='90' textAlign='Right'></e-column>
    </e-columns>



Best regards,
M


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 15, 2020 04:39 PM UTC

Hi Customer, 
 
Query#:- Could you provide me an example for dynamic columns from the " example" and biding for the combobox filter - Priority? 
 
We have modified the solution in the provided sample(with Dynamic columns) and performed Filtering for Priority column.   
 
Refer to the modified sample Link:- https://stackblitz.com/edit/angular-jgqh9d-kigp47 
 
Screenshot:- 
 
 
 
Refer to the documentation about filter hierarchy modes given below:- 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Farveen sulthana T 



MM MM December 17, 2020 01:37 PM UTC

Thank you for the quick answer. 
There is still strange behavior if I bind the combobox in the tree grid control.

Let's that in data (jsontreegriddata.ts) I have only "Id" property from the task data (in json data  === is Id from taskData), 
and I am showing "Priority" property in the list. 

Also, the list should contain editable combobox with the options ("Normal", "Low", "High")


Please take a look at the example:



FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 18, 2020 03:57 PM UTC

Hi Customer, 
 
Query#:- Let's that in data (jsontreegriddata.ts) I have only "Id" property from the task data (in json data   === is Id from taskData),  
 
From your query we suspect that you need to show the value to Priority column as like Foreignkey dataSource. In order to achieve this we suggest you to bind ForeignKey column as we have discussed in the documentation below 
 
Also in your provided code example, you have shown Id field for TreeGrid column which is not present in the TreeGrid dataSource. In order to perform TreeGrid actions, it is necessary to bind the field value which is present in TreeGrid dataSource. We have modified your sample to display priority column in TreeGrid and perform Filtering in it. 
 
Refer to the modified code below:- 
export class AppComponent { 
  @ViewChild("treegrid") public treegrid: TreeGridComponent; 
  public data: Object[] = []; 
  public taskData = [ 
    { Id: "1", Priority: "Normal" }, 
    { Id: "2", Priority: "Low" }, 
    { Id: "3", Priority: "High" } 
  ]; 
  public Combobox: any = new ComboBox({ 
    //set the data to dataSource property 
    dataSource: this.taskData, 
    change: args => { 
      var val = args.value; 
      if (!isNullOrUndefined(val)) { 
        var value = parseInt(this.taskData.filter(data => data.Priority === val)[0].Id) 
        this.treegrid.filterByColumn("priority", "equal", value); 
      } else this.treegrid.clearFiltering(); 
    }, 
 
    // maps the appropriate column to fields property 
    fields: { text: "Priority", value: "Priority" }, 
    // set placeholder to ComboBox input element 
    placeholder: "Select a task" 
  }); 
 
   
 
  private createTreeGridColumns() { 
    return [ 
      { field: "taskID", headerText: "Task ID", editType: "defaultedit" }, 
 
      { field: "startDate", headerText: "Start Date", editType: "defaultedit" }, 
    
      { 
        field: "priority",           //use Field which  is present in TreeGrid dataSource 
        headerText: "Priority", 
        valueAccessor: ((field, data, column) => { 
          if (data.priority !== "Critical") { 
            const mcref = this.taskData.find( 
              td => td.Id === data.priority.toString() 
            ); 
            console.log(mcref); 
            return mcref ? mcref.Priority : ""; 
          } 
        }).bind(this), 
        editType: "dropdownedit", 
        edit: { 
          params: { 
            query: null, 
            dataSource: this.taskData, 
            fields: { value: "Id", text: "Priority" } 
          } 
        } 
      }, 
       
      } 
    ]; 
 
 
</script> 
 
 
If your requirement is different from above, share detailed Explanation of your requirement to proceed further. 
 
Regards, 
Farveen sulthana T 
 



MM MM December 22, 2020 02:56 PM UTC

Thank you, this really helps.


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 23, 2020 04:34 AM UTC

Hi Customer,  

Thanks for your update. Please get back to us if you need any further assistance. We are happy to assist you. 

Regards, 
Farveen sulthana T 


Loader.
Up arrow icon