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


12 Replies 1 reply marked as answer

SJ Sridharan Jayabalan Syncfusion Team December 10, 2024 09:51 AM UTC

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



NV Niels Van Goethem December 12, 2024 09:53 AM UTC

Can I refresh the datasource in actionBegin



SJ Sridharan Jayabalan Syncfusion Team December 13, 2024 11:21 AM UTC

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



NV Niels Van Goethem December 13, 2024 01:11 PM UTC

Hello, I am referring to the actionBegin event inside additionalParams.
I want to refresh the datasource, as I have fetched new data. 

private loadEmployeeResources(searchTerm?: string): void {
    this.authorizationsService
      .getEmployees$(searchTerm)
      .pipe(
        tap((employees) => {
          this.resources = employees.map((employee) => ({
            id: employee.id,
            name: `${employee.firstName} ${employee.lastName}`,
          }));
          console.log(
            '🚀 ~ PlanningComponent ~ this.resources=employees.map ~ this.resources:',
            this.resources
          );
        }),
        takeUntil(this.destroy$)
      )
      .subscribe();
  }


SJ Sridharan Jayabalan Syncfusion Team December 14, 2024 09:58 AM UTC

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.

Let us know if you need further assistance. 

 

Regards,

Sridharan



NV Niels Van Goethem December 16, 2024 08:46 AM UTC

Hi, I am already updating the datasource. I am passing "resources" to the resources field:

<ejs-gantt
  #gantt
  height="650"
  [dataSource]="data"
  [resources]="resources"
  [taskFields]="taskSettings"
  [resourceFields]="resourceSettings"
  [columns]="columns"
  [labelSettings]="labelSettings"
  [allowSelection]="true"
  [projectStartDate]="projectTimelineStartDate"
  [projectEndDate]="projectTimelineEndDate"
  [highlightWeekends]="true"
  [gridLines]="lines"
  [toolbar]="toolbar"
  [editSettings]="isReadOnly ? readonlyEditSettings : editSettings"
  [enableUndoRedo]="!isReadOnly"
  [undoRedoActions]="undoRedoActions"
  [timelineSettings]="timelineSettings"
  [enableContextMenu]="true"
  (actionComplete)="onActionComplete($event)"
  (created)="onCreated()"
></ejs-gantt> And update the resources variable like in the code sample in my previous reply


SJ Sridharan Jayabalan Syncfusion Team December 17, 2024 10:11 AM UTC

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.

Instead, access the resourceTab's grid datasource instance when the edit dialog opens. After running your backend code, refresh the resourceTab's datasource within the 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



NV Niels Van Goethem December 17, 2024 11:56 AM UTC

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. 



NV Niels Van Goethem December 18, 2024 10:12 AM UTC

Also: is there an event when the search bar is cleared? So I can fetch the data without search string?



SJ Sridharan Jayabalan Syncfusion Team December 18, 2024 01:37 PM UTC

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



Marked as answer

NV Niels Van Goethem December 18, 2024 01:59 PM UTC

This works perfectly, thank you!



KG Kalpana Ganesan Syncfusion Team December 19, 2024 05:04 AM UTC

Hi Niels,


You're welcome, glad it worked for you. please get back to us for further assistance.


Regards,

Kalpana.


Loader.
Up arrow icon