JQGrid - 使搜索工作忽略大写,小写,$,逗号

时间:2015-01-06 00:54:38

标签: jquery jqgrid jqgrid-asp.net jqgrid-formatter

当我搜索下面的数字列时:年度结算:$ 7,749.19
如果我输入内置的搜索功能将不会显示记录:7749.19但是如果我把WYSIWYG作为7,749.19,我只能找到记录 必须有一些参数可以让搜索功能忽略逗号,$等。 我研究了它但却无法找到我能做到的方法。如果你能让我知道如何让搜索工作忽略大写,小写,$,逗号等,我将不胜感激。

我的代码在下面提供以供参考:

     $("#tblSiteLookup").jqGrid({

                url: 'Handlers/SitesHandler.ashx?l=sa&site=family&initiativeId=' + gblInitiativeID,
                datatype: "json",
                height: 250,
                width: 600,
                // autowidth: true,
                shrinkToFit: false,
                //forceFit: true,
                mtype: 'post',
                loadonce: true,
                colNames: ['CompanyGuid', 'Company', 'SiteGuid', 'Customer Site ID', 'Site Common Name', 'Service Street Address', 'Service City', 'Annual Consumption (kWh)', 'Annual Billing', 'OwnerId'],
                colModel: [
                            { name: 'CompanyGuid', hidden: true, sortable: false, editable: true },
                            { name: 'Company', search: true, width: 160, sortable: true, editable: true },
                            { name: 'SiteGuid', hidden: true, sortable: false, editable: true },
                            { name: 'CustomerSite', search: true, width: 100, sortable: true, editable: true },
                            { name: 'CommonName', search: true, width: 200, sortable: true, editable: true },
                            { name: 'StreetAddress', search: true, width: 250, sortable: true, editable: true },
                            { name: 'City', search: true, width: 110, sortable: true, editable: true },
                            { name: 'AnnualConsumption', search: true, width: 150, sortable: true, editable: true },
                            { name: 'AnnualBilling', search: true, width: 100, sortable: true, editable: true },
                            { name: 'OwnerId', hidden: true, sortable: false, editable: true },
                ],
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#pager11',
                sortname: 'Company',
                viewrecords: true,
                sortorder: "desc",
                caption: "Site"
            });

            $("#tblSiteLookup").jqGrid("setLabel", "Company", "", { "text-align": "left" });
            $("#tblSiteLookup").jqGrid("setLabel", "CustomerSite", "", { "text-align": "left" });
            $("#tblSiteLookup").jqGrid("setLabel", "CommonName", "", { "text-align": "left" });
            $("#tblSiteLookup").jqGrid("setLabel", "StreetAddress", "", { "text-align": "left" });
            $("#tblSiteLookup").jqGrid("setLabel", "City", "", { "text-align": "left" });
            $("#tblSiteLookup").jqGrid("setLabel", "AnnualConsumption", "", { "text-align": "left" });
            $("#tblSiteLookup").jqGrid("setLabel", "AnnualBilling", "", { "text-align": "left" });

            $("#tblSiteLookup").jqGrid('navGrid', '#pager11', { search: true, edit: false, add: false, del: false, searchtext: "search", refresh: false });


Server Side code : 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.SessionState;
using System.Web.Script.Serialization;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using System.Net;
using Microsoft.Xrm.Sdk;
using ESRCommon;
using ESRBusiness;
using ESRDomain;
using Microsoft.Crm.Sdk.BchXrm;
using BCH.DSM.XRM.Common;

namespace ESRWeb.Handlers
{
    /// <summary>
    /// Summary description for SitesHandler
    /// </summary>
    public class SitesHandler : IHttpHandler , IRequiresSessionState
    {

        #region Global Members

            private string _search = string.Empty;
            private int _numberOfRows = 0;
            private int _pageIndex = 0;
            private string _sortColumnName = string.Empty;
            private string _sortOrderBy = string.Empty;
            private string _command = string.Empty;
            private string _strOperation = string.Empty;
            private string _site = string.Empty;
            private string _initiativeId = string.Empty;

        #endregion
        /// <summary>
        /// Handle the request
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            System.Collections.Specialized.NameValueCollection forms = context.Request.Form;
            string SessionData = string.Empty;
            string sitesList = string.Empty;

            if (context.Session["SessionData"] == null)
            {
                context.Session["SessionData"] = "MySessionData";
            }
            else
            {
                SessionData = (string)context.Session["SessionData"];
            }


            _command = (request["l"] != null) ? request["l"] : "sa";
            _strOperation = forms.Get("oper");
            _site = (request["site"] != null) ? request["site"] : string.Empty;
            _initiativeId = (request["initiativeId"] != null) ? request["initiativeId"] : string.Empty;

            _search = (request["search"] != null) ? request["search"] : string.Empty;

            if (_strOperation == null)
            {
                if (_command == "sa" && _site == "family" && !String.IsNullOrEmpty(_initiativeId) && _initiativeId != "undefined")
                {
                    Guid initId = Guid.Parse(_initiativeId);
                    sitesList = GetSitesListByFamily(initId);
                    response.Write(sitesList);
                }

                if (_site == "all")
                {
                    sitesList = GetSitesList();
                    response.Write(sitesList);
                }

                if (_site == "query" && !String.IsNullOrEmpty(_search))
                {
                    sitesList = GetSitesList(_search);
                    response.Write(sitesList);
                }

            }
        }        

        private string GetSitesList(string _search)
        {
            XrmBusinessManager eum = new XrmBusinessManager();
            List<JsonSite> jsonListSites = new List<JsonSite>();
            JQGridResults result = new JQGridResults();
            List<JQGridRow> rows = new List<JQGridRow>();
            JQGridRow row = new JQGridRow();
            int id = 0;

            // Get the list of Sites
            jsonListSites.AddRange(eum.GetSitesListBL(_search));

            if (jsonListSites.Count > 0)
            {
                foreach (JsonSite site in jsonListSites)
                {
                    row.id = id;
                    id++;
                    row.cell = new string[10];

                    row.cell[0] = site.guid.ToString(); //hidden column
                    row.cell[1] = site.company;
                    row.cell[2] = site.bchSiteid.ToString(); //hidden column
                    row.cell[3] = site.bchName;
                    row.cell[4] = site.bchSiteCommonName;
                    row.cell[5] = site.bchServiceAddressLine1;
                    row.cell[6] = site.bchServiceAddressCity;

                    row.cell[7] = site.bchAnnualElectricConsumptionKwh;
                    row.cell[8] = site.bchAnnualBillingBase;
                    row.cell[9] = site.bchOwner;


                    rows.Add(row);
                }
            }

            // Total number of pages
            int total_pages = 0;
            _numberOfRows = 10;
            if (rows.Count > 0)
                total_pages = (rows.Count + _numberOfRows - 1) / _numberOfRows;


            result.rows = rows.ToArray();
            result.page = _pageIndex;
            result.total = total_pages;
            result.records = rows.Count;

            return new JavaScriptSerializer().Serialize(result);
        }

        private string GetSitesList()
        {
            XrmBusinessManager eum = new XrmBusinessManager();
            List<JsonSite> jsonListSites = new List<JsonSite>();
            JQGridResults result = new JQGridResults();
            List<JQGridRow> rows = new List<JQGridRow>();
            JQGridRow row = new JQGridRow();
            int id = 0;

            // Get the list of Sites
            jsonListSites.AddRange(eum.GetSitesListBL());

            if (jsonListSites.Count > 0)
            {
                foreach (JsonSite site in jsonListSites)
                {
                    row.id = id;
                    id++;
                    row.cell = new string[10];

                    row.cell[0] = site.guid.ToString(); //hidden column
                    row.cell[1] = site.company;
                    row.cell[2] = site.bchSiteid.ToString(); //hidden column
                    row.cell[3] = site.bchName;
                    row.cell[4] = site.bchSiteCommonName;
                    row.cell[5] = site.bchServiceAddressLine1;
                    row.cell[6] = site.bchServiceAddressCity;

                    row.cell[7] = site.bchAnnualElectricConsumptionKwh;
                    row.cell[8] = site.bchAnnualBillingBase;
                    row.cell[9] = site.bchOwner;


                    rows.Add(row);
                }
            }

            // Total number of pages
            int total_pages = 0;
            _numberOfRows = 10;
            if (rows.Count > 0)
                total_pages = (rows.Count + _numberOfRows - 1) / _numberOfRows;


            result.rows = rows.ToArray();
            result.page = _pageIndex;
            result.total = total_pages;
            result.records = rows.Count;

            return new JavaScriptSerializer().Serialize(result);
        }

        /// <summary>
        /// Get the list of Sites in a JQ Grid
        /// </summary>
        /// <returns>JQ Grid of End Uses</returns>
        private string GetSitesListByFamily(Guid initiativeId)
        {
            XrmBusinessManager eum = new XrmBusinessManager();
            List<JsonSite> jsonListSites = new List<JsonSite>();
            JQGridResults result = new JQGridResults();
            List<JQGridRow> rows = new List<JQGridRow>();
            JQGridRow row = new JQGridRow();
            int id = 0;

            // Get the list of Sites
            jsonListSites.AddRange(eum.GetSitesListByFamilyBL(initiativeId));

            if (jsonListSites.Count > 0)
            {
                foreach (JsonSite site in jsonListSites)
                {
                    row.id = id;
                    id++;
                    row.cell = new string[10];                  

                    row.cell[0] = site.guid.ToString(); //hidden column
                    row.cell[1] = site.company;
                    row.cell[2] = site.bchSiteid.ToString(); //hidden column
                    row.cell[3] = site.bchName;
                    row.cell[4] = site.bchSiteCommonName;
                    row.cell[5] = site.bchServiceAddressLine1;
                    row.cell[6] = site.bchServiceAddressCity;

                    row.cell[7] = site.bchAnnualElectricConsumptionKwh;
                    row.cell[8] = site.bchAnnualBillingBase;
                    row.cell[9] = site.bchOwner;


                    rows.Add(row);
                }
            }

            // Total number of pages
            int total_pages = 0;
            _numberOfRows = 10;
            if (rows.Count > 0)
                total_pages = (rows.Count + _numberOfRows - 1) / _numberOfRows;


            result.rows = rows.ToArray();
            result.page = _pageIndex;
            result.total = total_pages;
            result.records = rows.Count;

            return new JavaScriptSerializer().Serialize(result);
        }

        public bool IsReusable
        {
            // To enable pooling, return true here.
            // This keeps the handler in memory.
            get { return false; }
        }
    }

}

1 个答案:

答案 0 :(得分:0)

您可以通过更改jquery.jqGrid.src.js

中的某些行来实现此目的

在第4116行更换以满足您的要求。

例如,如果您要排除逗号(,),请添加.replace(/,/ g,&#39;&gt;&#39;)