Data source widget filtering

I’m having trouble filtering results in a data source widget. Shouldn’t I be able to use:

<arg id="filter" name="my_field" action="greater_than">0</arg>

to only display records in the data source where the numeric field ‘my_field’ is a positive, non-zero value?

So far, it is not filtering out anything and all the records, whether my_field = 0 or not, are showing. Is there a different syntax I should be using?

Thanks,

-= G =-

Hi G,

I think the quick answer to this one is that “data_source” is a custom module with its own filtering rules, it doesn’t inherit or follow most/any of the out-of-the-box LW widget filtering options. Basically anything you use in a data_source widget gets translated to mysql/oracle/csv/xml queries and sent to the outside source for data, so normal things like <arg id="filter" don’t get applied. I believe data_source uses search for all of its criteria; hope this helps! If you have more detailed queries/results processing, it may be that a standalone custom module or API integration is the answer, rather than using data_source.

Karl

is there any documentation on how to use search?

Thanks,

-= G =-

Here’s a related question:

In a data_source widget, when creating HTML I’m doing something like this:

<li data-value="{fieldname}">{another_fieldname}</li>

fieldname is numeric data - it works fine when fieldname is nonzero, then I get something like:

<li data-value="9">itemname</li>

but when the field = 0 I get:

<li data-value>itemname</li>

which is no good. I can output the value fine in other contexts, so:

<li>{fieldname} {another_fieldname}</li>

gives:

<li>0 itemname</li>

as expected. Is there any way to force the zero value to be put into the code?

Thanks,

-= G =-

Hi G,

Hmm, my guess is the underlying custom module code checks for !empty to populate that variable, so the falsey 0 is getting emptied out? You could try something using the widget formatting conditionals like data-value="{fieldname}{!fieldname:"0"}" and see if that fills the need here? Otherwise I think this would be a small project to update the module to fit that need.

And, heard on there not being sufficient documentation on that custom module – to my memory, it’s been deployed a few times over the years for particular projects (mostly course catalogs) and in each case we’ve tried to provide specific instructions for that one use case (i.e., use <arg id="search">dept_code=ANTH</span> for Anthropology courses) but I don’t think an effort has yet been undertaken to more broadly document the module for expanded or customized use cases. Let us know if that’s something you’d like more hands-on help with; thanks!

Karl

Thanks - that was the clue I needed to get the filtering I needed!

I will note, for anyone else trying to do this, that while this worked fine:

`<arg id="search">course_num>499</arg>`

This caused everything to break spectacularly:

<arg id="search">course_num<499</arg>

my guess is that the parser flipped out thinking we were about to open a tag. I finally got it to work, after much too-ing and fro-ing, this way:

<arg id="search">course_num&lt;499</arg>

-= G =-

1 Like