The below example demonstrates filtering with custom date format dd/mm/yy for Order Date column.
ShipCountry | Customer Name | Order ID | Order Date | Shipping Region | Paid | Shipping Via | Required Date | |
---|---|---|---|---|---|---|---|---|
- | - |
x1
2<div id="grid_filter" style="margin:5px auto;"></div>
3
1111
2$(function () {
3//function to change format from dd/mm/yy to mm/dd/yy and vice versa
4function changeFormat(value) {
5d1 = value ? value.split('/') : null;
6return value ? d1[1] + '/' + d1[0] + '/' + d1[2] : "";
7}
8function pqDatePicker(ui) {
9var $this = $(this);
10$this
11//.css({ zIndex: 3, position: "relative" })
12.datepicker({
13yearRange: "-25:+0", //25 years prior to present.
14changeYear: true,
15changeMonth: true,
16dateFormat: "dd/mm/yy"
17//showButtonPanel: true
18});
19//default From date
20var $from = $this.filter(".pq-from").datepicker("option", "defaultDate", new Date("01/01/1996"));
21//default To date
22var $to = $this.filter(".pq-to").datepicker("option", "defaultDate", new Date("12/31/1998"));
23
24var value = changeFormat(ui.column.filter.value),
25value2 = changeFormat(ui.column.filter.value2);
26
27$from.val(value);
28$to.val(value2);
29}
30
31//define colModel
32var colM = [
33{ title: "ShipCountry", dataIndx: "ShipCountry",
34filter: { type: 'textbox', condition: 'begin', listeners: ['keyup'] }
35},
36{ title: "Customer Name", dataIndx: "ContactName",
37filter: { type: "textbox", condition: 'begin', listeners: ['keyup'] }
38},
39{ title: "Order ID", minWidth: 130, dataIndx: "OrderID", dataType: "integer",
40filter: { type: 'textbox', condition: "between", listeners: ['keyup'] }
41},
42{ title: "Order Date", minWidth: "200", dataIndx: "OrderDate", dataType: "date",
43render: function (ui) {
44return changeFormat(ui.cellData);
45},
46filter: {
47type: 'textbox',
48condition: "between",
49init: pqDatePicker,
50listeners: [{ 'change': function (evt, ui) {
51
52ui.value = changeFormat(ui.value); //dd/mm to mm/dd
53ui.value2 = changeFormat(ui.value2); //dd/mm to mm/dd
54
55$(this).closest(".pq-grid").pqGrid('filter', {
56oper: "add",
57data: [ui]
58})
59}
60}]
61}
62},
63{ title: "Shipping Region", dataIndx: "ShipRegion" },
64{ title: "Paid", dataIndx: "paid", dataType: "bool", align: "center",
65filter: { type: "checkbox", subtype: 'triple', condition: "equal", listeners: ['click'] }
66},
67{ title: "Shipping Via", dataIndx: "ShipVia" },
68{ title: "Required Date", dataIndx: "RequiredDate", dataType: "date" },
69{ title: "Shipped Date", dataIndx: "ShippedDate", dataType: "date" },
70{ title: "Freight", align: "right", dataIndx: "Freight", dataType: "float" },
71{ title: "Shipping Name", dataIndx: "ShipName" },
72{ title: "Shipping Address", dataIndx: "ShipAddress" },
73{ title: "Shipping City", dataIndx: "ShipCity" },
74{ title: "Shipping Postal Code", dataIndx: "ShipPostalCode" }
75];
76
77var obj = {
78height: 500,
79colModel: colM,
80//pageModel: { type: "local", rPP: 50, rPPOptions: [10, 50, 100, 500, 1000] },
81virtualX: true, virtualY: true,
82wrap: false, hwrap: false,
83filterModel: { on: true, mode: "AND", header: true },
84title: "Shipping Orders",
85resizable: true,
86columnTemplate: { width: 150 },
87freezeCols: 2
88};
89
90var $grid = $("#grid_filter").pqGrid(obj);
91
92//load all data at once
93$grid.pqGrid("showLoading");
94$.ajax({ url: "/Content/orders.json",
95//url: "/pro/orders/get",//for ASP.NET
96//url: "/orders.php", //for PHP
97cache: false,
98async: true,
99dataType: "JSON",
100success: function (response) {
101var grid = $grid.pqGrid("getInstance").grid;
102grid.option("dataModel.data", response.data);
103
104grid.refreshDataAndView();
105grid.flex();
106grid.hideLoading();
107}
108});
109
110});
111