- Home
- Forum
- Angular - EJ 2
- Possible to search in the resources tab of the edit dialog?
Possible to search in the resources tab of the edit dialog?
Hello, I have not found this in the documentation. Is it possible to search in the resources tab? I don't mean filtering in the data that's already fetched by the client, but I mean search functionality with an event that I can catch, so I can send the search term to the backend
Hi Niels,
Greetings from Syncfusion.
To enable search functionality in the Resources tab of the edit dialog, you can utilize the editDialogFields property. Within this property, you can include a toolbar option inside additionalParams to enable a search bar. Additionally, by handling the grid's actionBegin event, you can capture the searched string and send it to the backend for further processing. Refer code snippet and sample for your reference.
Code-Snippet:
export class AppComponent { public ngOnInit(): void { (this.editDialogFields = [ { type: 'Resources', additionalParams: { toolbar: ['Search'], actionBegin(args) { if (args.requestType == 'searching') { console.log(args.searchString); // here you can send the value to back end } }, }, }, ]), } |
Sample - https://stackblitz.com/edit/angular-j6sbfqw3-yjoviayb?file=src%2Fapp.component.ts
Documentation - Managing tasks in Angular Gantt component | Syncfusion
Regards,
Sridharan
Can I refresh the datasource in actionBegin
Niels,
Thank you for reaching out to us. We would like to assist you effectively, but we need additional details to clarify your requirements. Could you please help us understand the following:
Are you referring to the Grid's actionBegin event inside the additionalParams? Or are you referring to the Gantt Chart's actionBegin event?
Could you elaborate on the purpose of the data source refresh you mentioned? Understanding this will help us provide a suitable solution for your needs.
Your clarification will ensure we address your queries accurately. Looking forward to your response.
Regards,
Sridharan
Hello, I am referring to the actionBegin event inside additionalParams.
I want to refresh the datasource, as I have fetched new data.
Niels,
Yes, you can refresh the dialog's grid data source inside the actionBegin event of the additionalParams after fetching the data from your backend. You can capture the search term in the actionBegin event when the requestType is searching, call your backend to fetch the updated data, and then update the grid's data source dynamically. This ensures the dialog reflects the latest data based on the search.
Regards,
Sridharan
Hi, I am already updating the datasource. I am passing "resources" to the resources field:
Niels,
For your query, we would like to clarify how to refresh the resourceTab's grid datasource. Because you are trying to manipulate the resource datasource assigned for Gantt chart. But Gantt chart has two datasources—one for tasks and another for resources. Avoid modifying the "editingResources" data assigned to the resources property of the Gantt chart.
actionBegin event using additionalParams. This will ensure the updated datasource is displayed in the resource tab.Code-Snippet:
export class AppComponent { public editDialogFields: any; public ngOnInit(): void { this.data = editingData; (this.editDialogFields = [ { type: 'Resources', additionalParams: { actionBegin(args) { var resGridComponent = ( document.getElementById( this.element.id + '_gridcontrol' ) as any ).ej2_instances[0]; if (args.requestType == 'searching') { console.log(args.searchString); // here you can send the value to back end // make any changes with the resGridComponent's datasource and refresh resGridComponent.refresh(); } }, }, }, ]), (this.resources = editingResources); // assigned for Gantt chart, no need to manipulate this datasource } } |
Modified Sample - Nb8emknq (forked) - StackBlitz
Regards,
Sridharan
Hi, I am still stuck with this. From your code sample, there is no way to call a service that fetches the resources, because "this" does not refer to my component. When I use an arrow function, I cannot use "this.element" anymore, as it does not exist in my component.
Also: is there an event when the search bar is cleared? So I can fetch the data without search string?
Niels,
Query 1 - there is no way to call a service that fetches the resources, because "this" does not refer to my component. When I use an arrow function, I cannot use "this.element" anymore, as it does not exist in my component.
We have updated the code to better suit the usage of arrow functions. You can use public variables to access the Gantt instance within the additionalParams section. By leveraging Angular's @ViewChild decorator, you can get the Gantt instance and use it in your arrow functions. Refer to the code snippet below for details:
Code-Snippet:
app.cpmponent.ts:- import { Component, OnInit, ViewChild } from '@angular/core'; import { GanttAllModule, GanttComponent } from '@syncfusion/ej2-angular-gantt'; export class AppComponent { @ViewChild('gantt') public gantt: GanttComponent; public ngOnInit(): void { (this.editDialogFields = [ { type: 'Resources', additionalParams: { toolbar: ['Search'], // Arrow function to call the handler actionBegin: (args: any) => this.onResourceSearch(args), }, }, ]), (this.resources = editingResources); } public onResourceSearch(args: any) { // Access Gantt instance using ViewChild var ganttInstance = this.gantt; if (ganttInstance && args.requestType === 'searching') { console.log(args.searchString); // Accessing the resource grid instance dynamically var resGridComponent = ( document.getElementById( ganttInstance.element.id + 'ResourcesTabContainer_gridcontrol' ) as any ).ej2_instances[0]; // Perform operations on the resource tab's grid resGridComponent.refresh(); } } } app.component.html:- <ejs-gantt #gantt > </ejs-gantt> |
Query 2 - is there an event when the search bar is cleared? So I can fetch the data without search string?
Yes, you can use the toolbarClick event inside the additionalParams for clear action. Refer to the screenshot below for details about the "args" available during the clearing action.
Code-Snippet:
app.cpmponent.ts:- export class AppComponent { public ngOnInit(): void { (this.editDialogFields = [ { type: 'Resources', additionalParams: { toolbar: ['Search'], toolbarClick: (args: any) => this.onToolbarClick(args), }, }, ]), (this.resources = editingResources); } public onToolbarClick(args: any) { //while clear icon is pressed, this event will hit } } |
Modified Sample - Nb8emknq (forked) - StackBlitz
Regards,
Sridharan
This works perfectly, thank you!
Hi Niels,
You're welcome, glad it worked for you. please get back to us for further assistance.
Regards,
Kalpana.
- 12 Replies
- 3 Participants
- Marked answer
-
NV Niels Van Goethem
- Dec 9, 2024 08:32 AM UTC
- Dec 19, 2024 05:04 AM UTC