Articles in this section
Category / Section

How to perform search operation programmatically in React File Manager?

11 mins read
Step 1: Implement File Manager component using our getting-started documentation.

Step 2: To perform search operation in the React File Manager component, you can utilize the created event and in the event handler, obtain the search input element and attach an event listener to it. Consequently, user input triggers the execution of the function inside the event listener.

Step 3: You can utilize the File Manager beforeSend event to disable the default search functionality. This was achieved by setting args.cancel as true.

Step 4: Finally, employ the File Manager filterFiles method and provided the search value to filter files and folders. This API method triggers the controller part with “filter” action.

This approach allows you to filter the files and folders within the File Manager component using external Dialog component.


[index.js]


const Overview = () => {

  let hostUrl = 'http://localhost:62869/';

  let fileObj;

 

  const beforeSend = (args) => {

    if (args.action == 'search') {

      args.cancel = true;

    }

  };

 

  const OnCreated = (args) => {

    let searchTimer;

    setTimeout(() => {

      document

        .getElementById('filemanager_search')

        .addEventListener('input', function (args) {

          const searchValue =

            document.getElementById('filemanager_search').value;

          clearTimeout(searchTimer);

          if (searchValue.length >= 3) {

            performSearch(searchValue);

          } else {

            // If the user types fewer than 3 characters, wait for 3 seconds and then perform the search

            searchTimer = setTimeout(() => {

              performSearch(searchValue);

            }, 3000); // Adjust the delay in milliseconds (3000ms = 3 seconds)

          }

        });

    }, 50);

  };

 

  function performSearch(value) {

    // Perform the search operation here with the value

    var objectValue = { searchString: '*' + value + '*' };

    fileObj.filterFiles(objectValue);

  }

 

  return (

    <div>

      <div className="control-section">

        <FileManagerComponent

          id="filemanager"

          ref={(s) => (fileObj = s)}

          ....

 

          view={'Details'}

          beforeSend={beforeSend.bind(this)}

          created={OnCreated.bind(this)}

        >

          <Inject services={[NavigationPane, DetailsView, Toolbar]} />

        </FileManagerComponent>

      </div>

    </div>

  );

};


[FileManagerController.cs]

[Route("FileOperations")]

public object FileOperations([FromBody] FileManagerDirectoryContent args)

{

    ....

 

    switch (args.Action)

    {

        ....

 

        case "filter":

            return this.operation.ToCamelCase(this.operation.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive));

    }

    return null;

}

Sample: https://stackblitz.com/edit/react-eydkub-qhlsab?file=index.js


Servicehttps://github.com/SyncfusionExamples/ej2-aspcore-file-provider


Conclusion

I hope you enjoyed learning on how to perform search operation programmatically in React File Manager.

You can refer to our React File Manager feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React File Manager Example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!
Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied