Datepicker-Filter using for FROM/TO-Filter

QuestionsDatepicker-Filter using for FROM/TO-Filter
Dirk asked 11 years ago

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

8 Answers
Abu Ghufran answered 11 years ago

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.

Abu Ghufran answered 11 years ago

You can also set limited search operators (e.g. gt = greater than) with date field.

$col["searchoptions"]["sopt"] = array("gt");

Dirk answered 11 years ago

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

Abu Ghufran answered 11 years ago

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)";

Dirk answered 11 years ago

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

Dirk answered 11 years ago

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?

Abu Ghufran answered 11 years ago

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");

Dirk answered 11 years ago

Thanks a lot! That solved my problem and it works now.

🙂

Your Answer

8 + 3 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?