List Manager Forum

Custom filtering from an HTML link

User Alex King 2024-10-24 20:43:57

We would like to have a custom piece of html in a column that allows a table to be filtered by a particular column value. For example, if we had a 3 column table as follows:

id colour
1 green
2 blue
3 pink

we'd like to be able to have a link something like: <a href="...//?id=2">click here for blue</a> so that when the link was clicked, only the column with id value 2 would be listed.

We've been able to get this effect by providing parameters to the page, for example like this:
https://<webaddress>/index.php/colours?lm_s=2&lm_e=id"

but then we are stuck on the https://<webaddress>/index.php/colours?lm_s=2&lm_e=id" page; other queries from there are constrained to this page, which isn't ideal. We really want to be back at https://<webaddress>/index.php/colours once we've done the search. We've looked at the page source and it seems the technique seems to be to post to the url (there is a call to 'post2url' we think) so would be good to know how to do that.

We've played about with custom Javascript but not having much luck!


Moonsoft support 2024-10-25 09:55:39

Hi,
right, once you have set the parameters at the url, then the view you'll get from the list will include those filters by default. In order to launch any specific filter but keep the main list view so you can restart/filter again using other filters, we'd suggest the following approach instead:

- Create a filter using your 'id' column (type text) and include it at the layout
- Now at the link, instead of calling the url with the parameters, call to a new js function, for ex 'callmyfilter(value)'. Where value should be the proper value of each row
- At the js section, create the callmyfilter function. It should fill the manual filter and launch the search. You can profit the jQuery alias we have for the list, which is $_lm. For launching the filter, you can launch a enter keypress event.
Here a js example we've just built to achieve this, please let us know if you need further details about this section.

function callmyfilter(value){
var e = jQuery.Event("keypress");
e.which = 13;
e.keyCode = 13;
$_ms('').val(value).trigger(e);
}

//You'd only need to replace the 'col1' with your column name to address the proper filter.


-Finally, if you don't want to show the manual filter to your users at the page, you can hide it using js as well.


Hope it helps, regards
Silvia Martín
Moonsoft Team

User Alex King 2024-10-25 21:12:40

This is great thanks and works well when filtering within the same page.

Is it possible to do something similar but link to another page? So a bit like when you have a field marked as 'Link to other list'?

Moonsoft support 2024-10-28 10:15:01

Hi,
it would be more complex, but we think it could be done with some more of code, maybe you could create a link to forward to 'another' page (that should be the same page but with your parameters). Same way the link to other list, but instead of
https:///index.php/colours?lm_s=2&lm_e=id
you should rename the parameters

https:///index.php/colours?myvalue=2&myfield=id

that way the system won't pre-filter automatically when another action is done afterwards. At the page, you will need to capture the url parameters on page load, and then use the same strategy explained above, fill the manual filter and launch it with the key event, that should do the work.


Hope this helps, regards
Silvia Martín
Moonsoft Team

User Alex King 2024-10-28 20:38:47

Great - thanks for all your help! I think it works with the following call to get to the other page:

history.pushState({}, "", <new page url>);

then the filtering code as you suggested previously seems to apply from the new page url.

...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!
...
List Manager

Build different lists for your site

Buy now!