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
I’m regenerating this issue and will be updating back after some testing.
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
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.