Forum

Thread tagged as: Question

Add search field to collections table in backend?

Is there an easy way to add a search field to the collections table in the Perch backend? Perhaps similar in functionality to DataTables jQuery plugin: https://datatables.net/

We recently built a website for a manufacturing company with 160 or so fairly similar products, and they've expressed frustration at the difficulty of finding particular items in the product collection (to update descriptions, photos, etc... which they are doing fairly often). It would be nice to customize this table a bit – specifically, to add a search field and change the number of results per page.

What would be the best way to go about this?

Josh Worden

Josh Worden 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you tried the search in the top bar?

Yes, but the results are all over the place and are only frustrating for the client. For instance, if they search by the product model id (one of the fields in the product collection), the actual item in the collection isn't included in the search results, however, other products mentioning that model id in their descriptions show up (along with other random text regions across the site). I'd like to be able to narrow that search.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, we'll keep that in mind.

In the meantime, is there anyway that we can add this feature ourselves without hacking the core? It would be fairly easy to implement:

1) Small changes to the html of the collections result table

2) Inserting the DataTables JS/CSS (which it looks like we can through the _config.inc file

What's the easiest way to achieve step 1?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to do that with JavaScript if anything.

Or you could implement your own app for searching.

Ahh, yes I can see how it would be done with JS, but we'd need the entirety of the table in the DOM. Is there a way to change the number of results per page on the collections table?

Josh, I would suggest you make what I call a “Micro App”

Basically all your app will do is query the tables of another app and report the data in a format which best meets your requirements. You can even send data to template. This way you control the amount of data you receive in a query, the format in which it reports and your not modifying any data. It’s a win-win as far as I see it.

A JS solution will still have you limited to the dataset being already output, which sounds in this case not to be big enough.

Just the thoughts rolling around my head... :)

Thanks Robert. I'll look into that. Drew, would you suggest the same?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's what I suggested above.

Great, thanks again.