grid date search
Hi Low,
I have posts which contain Low Events dates, this tels the visitor how long an event will be available for visiting shows. But when the shows runs for about 3 months there are only,for example 4 dates on which the show will be actually be played.
I use the Grid fielf with date fieldtype to create a list of those 4 (play)dates.
Now if i want to filter the posts to see if this week the show is going to take place i use the Low Serch form below. But is searches only the Low Events Dates and not the (play)dates from the grid fieldtype.
How can I create a seach input ,using my radiobuttons/checboxes, to filter that grid date field in the way as 'm using it now withe the value="now;+7 days" ?
Any thoughts?
{exp:low_search:form
query="{segment_3}"
result_page="agenda/results"
form_id="search"
}
<input type="radio" name="low_events:date" id="this-week" class="css-checkbox" value="now;+7 days">
<label for="this-week" class="css-label">Deze week</label>
<button class="vote" type="submit">Zoek</button>
{/exp:low_search:form}
Replies
Low 31 Mar 2015 13:17
If you're targeting a Grid column, you'll need to use the Field Search filter.
For that, you would need to create timestamp vars for now ({current_time}) and 1 week from now, for example, like explained here.
Then feed those to the param: search:grid_field:date_col=">=123|<=456" where 123 and 456 are the dates.
Otherwise, you'd need to create an extension or custom filter to allow for this more elegantly.
Dave 31 Mar 2015 14:17
I don't really understand yet but, is this the general idea for problem (the code below)?
And could I create this timestamps vars by using Low_Variables?
<input type="radio" name="search:playdates:dates" id="this-week" class="css-checkbox" value="{lv_current_time+7days}">
<label for="this-week" class="css-label">Deze week</label>
I really don't get you last line at the end >=123|d could you explain this..?
Thanks for you're effort.
Low 31 Mar 2015 14:26
No, creating a relative date with {lv_current_time+7days} won't work. You'll have to use PHP in your template or create a variable in your config file.
For example, if you add this to your config file:
then you should be able to use this as a parameter:
Dave 2 Apr 2015 06:59
Hi Low,
I created the the variables i need in the config and they seem to work because in the source code of my template i can see Low Search wants to search between two number that equals time.
<input type="radio" name="search:speeldata:test" value=">={current_time}|<={today}" id="grid-this-today" class="css-checkbox" >
<label for="grid-this-today" class="css-label"><p>Vandaag</label>
<input type="radio" name="search:speeldata:test" value=">=1427957607|<=1428044007" id="grid-this-today" class="css-checkbox" >
<label for="grid-this-today" class="css-label">Vandaag</label>
But unfortuantly the post I'm seacrching for doesn't show up, I tested it again with an the exact (date of the gridfield) value into the Search Filter and then the post does turn up.
This is the date from the gridfield wihich oututs this in the sourcecode 1427962320
.
<input type="radio" name="search:speeldata:test" value="1427962320" id="grid-this-test" class="css-checkbox" >
<label for="grid-this-test" class="css-label">Vandaag - vaste - waarde </label>
Hope you can see what i'm doing wrong..
Thanks.
Low 2 Apr 2015 07:28
Try using this as a value instead:
Also, you might need to check what the datatype of the date column in the database is. Look for a exp_channel_grid_field_X table, with a col_id_Y column, where X is the grid field ID, and Y is the date column ID.
The column should be an INT, while EE creates it as a varchar, which makes ranges unreliable.
Dave 2 Apr 2015 10:26
Hi Low,
Yhat seems to be wroking!
I don't really understand what you are asking about the databsa. But if found the field an its columns and the look like this,
Low 2 Apr 2015 10:29
If it works, there's no immediate need to change the column type from varchar to int.
Dave 2 Apr 2015 10:37
It pulled only the one post up, which i was testing. I meant the && worked.
But my databse isn't INT but varchar?
I will do some more testing with several posts en dates. If I run in to diffeculties I will let you know.
Say hello to the duck for me..
Low 2 Apr 2015 10:43
Changing the column from varchar to int will allow for better searching. When the field is varchar, the text will be considered text, not a number, and ordered accordingly.
That means '0100' < '0150' and '100' > '0150', just like 'abaa' < 'abca' and 'baa' > 'abca'.
Changing the field to INT will ensure the values are considered numeric.
However, all the date values will be 10-digit numbers, so ordering/filtering like text or numbers will have the same results.
Dave 15 Apr 2015 11:24
Hi Low,
I have another question for the same kind of problem. Can Low Search also search when the input for the form is a date picker?
I now have Mootools DatePicker set up as an input field in the search from, but what to do whit the value. Have any experience on using a datepicker with LowSearh?
Thanks,
Dave
Low 15 Apr 2015 12:34
If you're using the Ranges filter, any date format is accepted, as LS will transform that to a timestamp itself.
Since you're not using the Ranges filter, but the Field Search filter, you'd need to submit timestamps yourself. So, if the datepicker can generate a timestamp, use that.