FilterValue and URL parameter lost when ordering

SteveRL

Member
I have a module outside of Fabrik that gets the value of a filter or URL parameter and uses it to display some related information about the record. This one module works on multiple lists, which is why there are so many if else statements. The code I'm using to get the value is below. It's actually working very well, however when I try to order any column, I lose the ID in the module and get "ID not detected". Is there a way to maintain/add a URL parameter when ordering? Or some other way to get the value of the filter? The filter is still active on the correct item, but for some reason FabrikHelperElement::filterValue doesn't have a value when you order a column. Appreciate any input, Thanks.

PHP:
$db =& JFactory::getDBO();
$ad_filter = FabrikHelperElement::filterValue(270);
$sb_filter = FabrikHelperElement::filterValue(287);
$ann_filter = FabrikHelperElement::filterValue(127);
$cal_filter = FabrikHelperElement::filterValue(253);
$com_filter = FabrikHelperElement::filterValue(99);
$hor_filter = FabrikHelperElement::filterValue(82);
if (!empty($ad_filter)) {
//echo "Yes, ad filter is set, pulling filter value";
$record = $ad_filter;
}else if (!empty($sb_filter)) {
$record = $sb_filter;
}else if (!empty($ann_filter)) {
$record = $ann_filter;
}else if (!empty($cal_filter)) {
$record = $cal_filter;
}else if (!empty($com_filter)) {
$record = $com_filter;
}else if (!empty($hor_filter)) {
//echo "Yes, hr filter is set, pulling filter value";
$record = $hor_filter;
}else if (isset($_GET['AD___item_id_raw'])){ 
//echo "Filter is not set, check URL, found AD ID";
$record = $_GET['AD___item_id_raw'];
}else if (isset($_GET['SB___item_id_raw'])){ 
//echo "Filter is not set, check URL, found SB ID";
$record = $_GET['SB___item_id_raw'];
}else if (isset($_GET['Ann___item_id_raw'])){
//echo "Filter is not set, check URL, found Ann ID";
$record = $_GET['Ann___item_id_raw'];
}else if (isset($_GET['Com___item_id_raw'])){
//echo "Filter is not set, check URL, found Com ID";
$record = $_GET['Com___item_id_raw'];
}else if (isset($_GET['Insp___item_id_raw'])){
//echo "Filter is not set, check URL, found Inspection ID";
$record = $_GET['Insp___item_id_raw'];
} else {
    echo "ID not detected";
goto skip;
}
 
The problem is probably that the FabrikHelperElement::filterValue() isn't using the right 'listref'. The filterValue() helper has to know which list is being referenced, so it can get the correct data from the session data (you could have multiple lists on a page, so every list's filter data is stored with a unique key in the session).

When loading a page, Fabrik has a pretty good idea about what list is being built, but during AJAX operations, you have to specify it. Every list related AJAX call we make, we include the 'listref' in the posted data. Including when ordering ... if you open dev tools (ctrl-shirt-I in Chrome) and look at the Network tab, and do an order operation, you'll see the AJAX call fire off, and in the request data is the listref:

https://www.screencast.com/t/nmcHyH30ckf

And the FabrikHelperElement::filterValue() lets you specify a listref as the second parameter.

So try this:

Code:
$app = JFactory::getApplication();
$listref = $app->input->get('listref', '');
$ad_filter= FabrikHelperElement::filterValue(270, $listref);

... and add listref to all your filterValue() calls. It won't have a value when the page is first being built, but filterValue() will ignore it and use the default if it's empty.

-- hugh
 
This is awesome Hugh, I can tell this is what I'm looking for, however I think I'm using it incorrectly or missing something. If I include the listref, I do get the value of the filter when ordering (and when the page loads if listref is hard coded). Perfect.

But when I try to use that value to load a form in my module like this:
Code:
echo '{fabrik view=details id=13 rowid=';
echo $record;
echo ' fabrik_show_nav=0 hide-add=1 showfilters=0 show-title=0}';
I get errors like Unknown column '276' in 'order clause'. 276 is the element I ordered by in the list on the main page. So it appears it's trying to also order my details view in the module and obviously it doesn't have element 276.

As a test I changed my module to echo the same list displayed on the main page, it works without errors, and if I order on the main page, the order is also reflected in the module list.

Any ideas?
 
Without setting up an identical test case here, I can't really tell you anything. And that's not something I can do in Community support.

-- hugh
 
Can we move this to the Standard Support forum please. Also I submitted payment the other day and don't see that I have post privileges in Standard.

I have greatly simplified my code/case for testing. Basically where I'm at is I have unpublished the module with the php code and I've put the follow one line in a lists footer text.
Code:
{fabrik view=details id=13 rowid=1}
When I then view the list, I see the form details record at the bottom. However, when I try to order anything in the list, I receive: Unknown column '295' in 'order clause'

I feel like you should be able to replicate this unless there is some underlying problem with my site. Also I have noticed that it works randomly, maybe 1 in 20. So if it works for you out of the gate, try refreshing and ordering the list several times.
 
Any thoughts on this one? I added that one line to the 'Annual' list footer so you can login and see the error (when the Annual list is ordered). If I Ajaxify the Annual list it doesn't error when ordering but that wont work for me because in the end I need the details views rowid to match the lists filter. I don't suppose there is a way to refresh the page on filter action but use ajax on ordering? That would solve the problem.
 
Hi Hugh, did you ever have a chance to look at this? Is it something specific to my config or can you replicate it?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top