Daterange picker

QuestionsDaterange picker
Danish Zafar asked 3 years ago

I am using daterange picker (on column) with a set-on-load filter (1 month range), and i have multiple drop downs search filters on other columns (like user, transaction type). The grid loads the one month data correctly(as set in the load filter), but whenever any of these column search dropdown is selected, the grid ignores the load filter date range criteria and shows all the data.

a. Kindly advise how can i restrict the column filters to follow the load filter JSON OR
b. How can i force daterange picker to select a date range on load(say a month), so other column filters should query the same date range as pre selected in the date range. As currently the daterange picker dont pre-select any date range, the grid load date range from JSON.

Code:

// date_default_timezone_set(‘Asia/Karachi’);
$datetime = new DateTime(‘-1 month’);
$v1 = $datetime->format(‘Y-m-d’);
$datetime = new DateTime(‘today’);
$v2 = $datetime->format(‘Y-m-d’);

$sarr = <<< SEARCH_JSON
{
“groupOp”:”AND”,
“rules”:[
{“field”:”tran_date”,”op”:”bt”,”data”:”{\”start\”:\”{$v1}\”,\”end\”:\”{$v2} \”}”}
]
}
SEARCH_JSON;
$grid[“search”] = true;
$grid[“postData”] = array(“filters” => $sarr );

 

$col = array();
$col[“title”] = “Date”;
$col[“name”] = “tran_date”;
$col[“width”] = “120”;
$col[“align”] = “center”;
$col[“formatter”] = “date”;
$col[“formatoptions”] = array(“srcformat”=>’Y-m-d’,”newformat”=>’d/m/Y’);

// date range filter in toolbar
$col[“stype”] = “daterange”;

// Update options for date range picker: http://tamble.github.io/jquery-ui-daterangepicker/#options
$col[“searchoptions”][“opts”] = array(“initialText”=>”Select range…”);

$cols[] = $col;

Screenshot

View post on imgur.com

5 Answers
Abu Ghufran Staff answered 3 years ago

I’m regenerating this issue and will be updating back after some testing.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Danish Zafar answered 3 years ago

Hope you get a solution soon to lock the JSON searching, meanwhile i tried the following way around under function link_daterange_picker(el,opts) in jqgrid_dist.php

var priorDate = moment().subtract(‘days’, 30).startOf(‘day’).toDate();
jQuery(el).daterangepicker(“setRange”, {start: priorDate, end: moment().startOf(‘day’).toDate()});

Now this is locking the the daterange column with a preset range on load (this 30 days range matches with my JSON postData)and allows user to play with other column selectors without loading the whole data in select_command.

Kindly advise if this approach is OK?

Thanks

Abu Ghufran Staff answered 3 years ago

I’ve created a demo to solve this case. The solution you mentioned changes the base library and will impact all other grids as well which don’t need such daterange locking.

I’m emailing you a library update and a demo which shows how to solve it.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Danish Zafar answered 3 years ago

Great ! Thanks for your support 🙂

Samuel answered 1 year ago

Can you please send to me the or post the solution here?

Your Answer

16 + 13 =

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?