Jqgrid realizes pure front-end filtering (and all data is loaded at one time, filtering at the front end)

Source: Internet
Author: User
Tags jqgrid
/* Jqgrid Front-End filtering function */function Gridsearch (GRID) {//clone object this.clone_obj = function (data) {var D;
            if ($.type (data) = = ' array ') {d = [];
            For (i in data) {D[i] = Data[i];
            }}else if ($.type (data) = = ' object ') {d = {};
            For (i in data) {D[i] = Data[i];
        }}else{d = data;
	return D; ///Deletes the specified element this.delete_val_by_key = function (keys, arr) {for (var j=0,i=0; i<keys.length; i++) {Arr.splice) based on the key value
			(Keys[i-j], 1);
		j + +;
	return arr;
    } This.grid = grid;
    This.result = [];
	This.search_param = null;
    THIS.R = [];
    This.data = [];
		if (This.data.length = = 0) {var data = $ (GRID). Getgridparam (' Readonlydata ');
    This.data = this.clone_obj (data);
	
    }//console.log (This.data.length);
    Initialization result This.init_result = function () {This.result = This.clone_obj (This.data);
	}//Initialize R this.init_r = function () {THIS.R = [];

}    Sets the filter parameter This.set_search_param = function (search_param) {this.search_param = Search_param;
        }//Filter rule/* Blur filter/this.vaguesearch = function (str, column) {This.init_r ();
		var re = new RegExp (str, "I");
        var is = []; for (var i=0; i<this.result.length; i++) {if (Re.test (This.result[i][column))) {This.r.push (this.clone_ob
				J (This.result[i]));
            Is[is.length] = i;
		}//This.result = This.delete_val_by_key (is, this.result);
    This.result = This.clone_obj (THIS.R);
		/* Interval Lookup/* This.betweensearch = function (start, end, column) {This.init_r ();
        var is = []; for (var i=0 i<this.result.length; i++) {if (this.result[i][column) >= start && this.result[i
				][column] <= end) {This.r.push (This.clone_obj (this.result[i)));
            Is[is.length] = i; }//This.result = This.delete_val_by_key (IS, This.result);
    This.result = This.clone_obj (THIS.R);
		
        //////* This.select = function (params) {//var rule_name = Params.rule_name, based on parameter selection rules;
                Switch (params.rule_name) {case ' between '://console.log (This.result);
                This.betweensearch (Params.start, Params.end, Params.column);
            Break
                Case ' vague ': This.vaguesearch (Params.str, Params.column);
        Break
    }/* Empty result */This.clearresult = function () {this.result = [];
        ///Perform filter this.search = function () {this.init_result ();
		
        This.init_r (); if (This.search_param) {if ($.type (this.search_param) = = ' array ') {for (var i=0; I <= This.sea Rch_param.length;
					i++) {if (This.search_param[i]) {this.select (this.search_param[i]);
            }}else{This.select (This.search_param);
		
}
        }        Reload Data $ (' #table_list_1 '). Jqgrid (' Cleargriddata ');
		$ (This.grid). Jqgrid (' Setgridparam ', {data:this.result}). Trigger (' Reloadgrid ');
		This.clearresult ();
    This.init_r (); }
}

Instructions for use:

You need to add a Readonlydata attribute at initialization time, and the value is null to hold the data that is loaded. All filters are filtered for this property value data.

Use the following code

var search_param = new Array (); Used to save the filter rule
search_param.push ({rule_name: ' Between ', Start:start_date,end:end_date,column: ' Datatime '}); Filter rules need to be set according to the rule function rule_name: rule name, each rule name corresponding to a method, can be viewed through the Select method; The following property options are the parameters of the corresponding function of the rule

var a = new Gridsearch (' #table_list_1 ');//Create Instance
A.set_search_param (Search_param); Commit the Setup Rule
a.search ();//Perform a search




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.