Hi,
I have a table with 2 date fields (FromDate, ToDate) and I want to use SearchFilter/DatePicker that way, that if a concrete FromDate is selected all the datasets with that FromDate OR LATER will be shown and not just those dataset matching the date.
Is there a chance to do that?
Thanks in advance,
Dirk
Hello Dirk,
If you are using licensed version, i can send you an update after which you can have such filters using search dialog (toolbar search button).
Email me from your payment address, at [email protected]
Apologies for the delay.
You can also set limited search operators (e.g. gt = greater than) with date field.
$col["searchoptions"]["sopt"] = array("gt");
Hi,
thanks for the reply! My actual problem is now, that the Date is provided as unix timestamp in the database and I do a formatting like this
$col = array();
$col["title"] = "Von";
$col["name"] = "startdate";
$col["formatter"] = "date";
$col["width"] = 100;
$col["formatoptions"] = array("srcformat"=>'U',"newformat"=>'Y-m-d');
$col["searchoptions"]["sopt"] = array("gt");
The date is shown correctly because of the format options. I dont know, how to do the same in the searchoptions.
Any idea?
Thanks in advance,
Dirk
Hello,
You can try using from_unixtime function is your select sql.
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtime
In this way, you will not need the formatting. And for searching in correct date format, set
$col["dbname"] = "from_unixtime(startdate)";
Thanks,
I like the idea but it still doesnt work.
That's how i did it
select FROM_UNIXTIME(startdate,'%Y-%m-%d') from xxx
$col = array();
$col["title"] = "Von";
$col["name"] = "FROM_UNIXTIME(startdate,'%Y-%m-%d')";
$col["dbname"] = " FROM_UNIXTIME(startdate,'%Y-%m-%d')";
$col["formatter"] = "date";
$col["width"] = 100;
$col["searchoptions"]["sopt"] = array("gt");
$col["editable"] = false;
$cols[]=$col;
I've tried it in several variations like:
select FROM_UNIXTIME(startdate,'%Y-%m-%d') as startdate from xxx
$col["name"] = "startdate";
but it never filtered correctly.
Any idea?
Thanks in advance,
Dirk
It's me again.
It looks to me, that the searchoptions – parameter is completely ignored for date fields and it always does a "eq"-comparison.
Using the FROM_UNIXTIME in the select works fine, but it always does an Equals-Filter. Since that works, I guess the sql and the other configurations are fine.
$col = array();
$col["title"] = "Bis";
$col["name"] = "enddate";
$col["dbname"] = " FROM_UNIXTIME(enddate,'%Y-%m-%d')";
$col["search"] = true;
$col["formatter"] = "date";
$col["width"] = 100;
$col["searchoptions"]["sopt"] = array("gt");
$col["editable"] = false;
$cols[]=$col;
Any idea?
You can override core lib for that. goto jqgrid_dist.php in lib/inc.
change this line (2 occurences)
$cols[$i]["searchoptions"]["sopt"] = array("eq","ne","gt","ge","lt","le");
to …
if (empty($cols[$i]["searchoptions"]["sopt"]))
$cols[$i]["searchoptions"]["sopt"] = array("eq","ne","gt","ge","lt","le");