Customer ID | Company Name | Contact Name | Contact Title | Address |
---|
Customer ID | Company Name | Contact Name | Contact Title | Address |
---|
x1
2<div id="grid_search" style="margin: auto;">
3</div>
4
1391
2$(function () {
3function filterhandler(evt, ui) {
4
5var $toolbar = $grid.find('.pq-toolbar-search'),
6$value = $toolbar.find(".filterValue"),
7value = $value.val(),
8condition = $toolbar.find(".filterCondition").val(),
9dataIndx = $toolbar.find(".filterColumn").val(),
10filterObject;
11
12if (dataIndx == "") {//search through all fields when no field selected.
13filterObject = [];
14var CM = $grid.pqGrid("getColModel");
15for (var i = 0, len = CM.length; i < len; i++) {
16var dataIndx = CM[i].dataIndx;
17filterObject.push({ dataIndx: dataIndx, condition: condition, value: value });
18}
19}
20else {//search through selected field.
21filterObject = [{ dataIndx: dataIndx, condition: condition, value: value}];
22}
23$grid.pqGrid("filter", {
24oper: 'replace',
25data: filterObject
26});
27}
28//filterRender to highlight matching cell text.
29function filterRender(ui) {
30var val = ui.cellData,
31filter = ui.column.filter;
32if (filter && filter.on && filter.value) {
33var condition = filter.condition,
34valUpper = val.toUpperCase(),
35txt = filter.value,
36txt = (txt == null) ? "" : txt.toString(),
37txtUpper = txt.toUpperCase(),
38indx = -1;
39if (condition == "end") {
40indx = valUpper.lastIndexOf(txtUpper);
41//if not at the end
42if (indx + txtUpper.length != valUpper.length) {
43indx = -1;
44}
45}
46else if (condition == "contain") {
47indx = valUpper.indexOf(txtUpper);
48}
49else if (condition == "begin") {
50indx = valUpper.indexOf(txtUpper);
51//if not at the beginning.
52if (indx > 0) {
53indx = -1;
54}
55}
56if (indx >= 0) {
57var txt1 = val.substring(0, indx);
58var txt2 = val.substring(indx, indx + txt.length);
59var txt3 = val.substring(indx + txt.length);
60return txt1 + "<span style='background:yellow;color:#333;'>" + txt2 + "</span>" + txt3;
61}
62else {
63return val;
64}
65}
66else {
67return val;
68}
69}
70var colModel = [
71{ title: "Customer ID", dataIndx: "customerid", width: 100, render: filterRender },
72{ title: "Company Name", width: 180, dataIndx: "companyname", render: filterRender },
73{ title: "Contact Name", width: 140, dataIndx: "contactname", render: filterRender },
74{ title: "Contact Title", width: 140, dataIndx: "contacttitle", render: filterRender },
75{ title: "Address", width: "170", dataIndx: "address", render: filterRender }
76];
77var dataModel = {
78location: 'remote',
79url: "/pro/customers/get"
80}
81var newObj = {
82scrollModel: { autoFit: true },
83height: 'flex',
84pageModel: { type: 'local' },
85dataModel: dataModel,
86colModel: colModel,
87filterModel: { mode: 'OR' },
88editable: false,
89showTitle: false,
90toolbar: {
91cls: "pq-toolbar-search",
92items: [
93{
94type: 'textbox',
95label: 'Filter: ',
96attr: 'placeholder="Enter your keyword"',
97cls: "filterValue",
98listener: { keyup: filterhandler }
99},
100{
101type: 'select', cls: "filterColumn",
102listener: filterhandler,
103options: function (ui) {
104var CM = ui.colModel;
105var opts = [{ '': '[ All Fields ]'}];
106for (var i = 0; i < CM.length; i++) {
107var column = CM[i];
108var obj = {};
109obj[column.dataIndx] = column.title;
110opts.push(obj);
111}
112return opts;
113}
114},
115{
116type: 'select',
117cls: "filterCondition",
118listener: filterhandler,
119options: [
120{ "begin": "Begins With" },
121{ "contain": "Contains" },
122{ "end": "Ends With" },
123{ "notcontain": "Does not contain" },
124{ "equal": "Equal To" },
125{ "notequal": "Not Equal To" },
126{ "empty": "Empty" },
127{ "notempty": "Not Empty" },
128{ "less": "Less Than" },
129{ "great": "Great Than" },
130{ "regexp": "Regex" }
131]
132}
133]
134}
135};
136var $grid = $("#grid_search").pqGrid(newObj);
137
138});
139