Easyui combogrid drop-down box smart input

Source: Internet
Author: User

1. Background code

Using System;
Using System.Collections;
Using System.Collections.Generic;
Using System.Linq;
Using System.Reflection;
Using System.Web;
Using Contract.domain;
Using Webapp.common;

Namespace Hraweb.common
{
<summary>
Summary description of Entityjsonlist
</summary>
public class Entityjsonlist:basepage, IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

Public PropertyInfo Getproperyinfo (string Name, propertyinfo[] PS)
{
PropertyInfo p1 = null;
Ps. ToList (). ForEach (p =
{
if (p.name = = Name)
{
P1 = p;
}
});
return p1;
}
public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
Context. Response.Cache.SetCacheability (Httpcacheability.nocache);
Switch (context. request["_method"])
{
Case "Entity":
String EntityType = context. request["EntityType"];
info = new Framework.queryinfo ();
Info. Queryobject = EntityType;
if (!string. IsNullOrEmpty (context. Request["where"]))
{
Info. Where.add ("KK", "and" + context.) Request["where"]);
}
var keyword = context. request["keyword"]?? String. Empty;
if (!string. IsNullOrEmpty (keyword))
{
Hashtable aa=new Hashtable ();
Aa. ADD (context. request["Querytextfild"]. ToString () + "_lk", keyword);
Info. AddParam (AA);
Info. Where.add ("Kk2", String. Format ("and {0} like '%:{1}% '", context. request["Querytextfild"],keyword));
}
Info. PageSize = Int. Parse (httpcontext.current.request["Rows"]);
int pageIndex = Int. Parse (httpcontext.current.request["page"]);
Info. Startrecord = (pageIndex-1) * Info. PageSize;
Info. TotalCount = 1;
if (!string. IsNullOrEmpty (context. request.querystring["Queryfild"]))
{
string[] field = context. request.querystring["Queryfild"]. Split (new char[] {' | '});
foreach (String q in field)
{
Info. AddParam (q, Context.) request.querystring["Q"], string. Format ("and {0} like '%:{0}% '", q));
}
}
info = dao.findbyqueryinfo (info);
Type type = NULL;
propertyinfo[] PS = null;
if (info. List! = null && info. List.count > 0)
{
Type = info. List[0]. GetType ();
PS = type. GetProperties ();
}
BOOL Idboolean = false;
foreach (var b in info.) List)
{

PropertyInfo Idfieldinfo = getproperyinfo (context. request["Idfild"], PS);
String idfieldvalue = Convert.ToString (Idfieldinfo.getvalue (b, null));
if (!string. IsNullOrEmpty (context. request["DefaultValue"]))
{
if (idfieldvalue.equals (context. request["DefaultValue"]))
{
Idboolean = true;
Break
}
}
}
if (!string. IsNullOrEmpty (context. request["DefaultValue"]))
{
Framework.queryinfo tmpinfo = new Framework.queryinfo ();
Tmpinfo.queryobject = EntityType;
if (!string. IsNullOrEmpty (context. request["Idfild"]))
Tmpinfo.addparam (context. request["Idfild"], context. request["DefaultValue"]);
var list = dao.findlist (Tmpinfo);
foreach (object obj in list)
{
if (!idboolean)
{
Info. List.add (obj);
}
}
}
Datagridjson d = new Datagridjson (info. TotalCount, Info. List);
HttpContext.Current.Response.Write (Newtonsoft.Json.JsonConvert.SerializeObject (d));
Break
Case "Dict":
var t = Getdicttype (context. request["Dicttype"]);
Ilist<sysdict> dictlist= holworth.utility.utility.listtot<sysdict> (t);
Two filters using LINQ based on keywords
var keyword2 = context. request["keyword"]?? String. Empty;
if (!string. IsNullOrEmpty (KEYWORD2))
{
Dictlist = dictlist.where (x = X.name.contains (Keyword2)). ToList ();
}
string ss = Newtonsoft.Json.JsonConvert.SerializeObject (dictlist);
Context. Response.Write (ss);
Break
Case "AA":
var ts = getdicttype (context. request["Dicttype"]);
String sss = Newtonsoft.Json.JsonConvert.SerializeObject (ts);
Context. Response.Write (SSS);
Break
}
}


public bool IsReusable
{
Get
{
return false;
}
}
}
}

2. Drop-down box entity foreground code

This. Setentitycombo = function (obj, EntityType, TextField, columns, where, Idfild, Queryfild) {
var url = '/common/entityjsonlist.ashx?entitytype= ' + entityType + ' &_method=entity&tmp= ' + math.random () + ' & ; querytextfild= ' + TextField;
if (where) {
URL + = "&where=" + where;
}
if (obj.val () = "") {
URL + = "&defaultvalue=" + obj.val ();
}

var id = ' ID ';
if (idfild) {
id = idfild;
}
URL + = "&idfild=" + ID;
if (queryfild) {
URL + = "&queryfild=" + queryfild;
// }
Obj.combogrid ({
PANELWIDTH:500,
Idfield:id,
Textfield:textfield,
Url:url,
Method: ' Get ',
delay:1000,
Pagination:true,//whether paging
Rownumbers:true,//serial number
Pagesize:10,//number of records displayed per page, default is 10
PageList: [10],//can set a list of the number of record bars per page
Columns:columns,
Striped:true,
Editable:true,
Collapsible:false,//Can be folded
Fit:true,//Auto Size
Keyhandler: {
Up:function () {//"up key" to defer processing
Access to selected BOC
var selected = Obj.combogrid (' grid '). DataGrid (' getselected ');
if (selected) {
Get the rowindex of the selected row
var index = obj.combogrid (' grid '). DataGrid (' Getrowindex ', selected);
Move up to the first action stop
if (Index > 0) {
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', index-1);
}
} else {
var rows = Obj.combogrid (' grid '). DataGrid (' GetRows ');
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', rows.length-1);
}
},
Down:function () {//"down arrow" to defer processing
Access to selected BOC
var selected = Obj.combogrid (' grid '). DataGrid (' getselected ');
if (selected) {
Get the rowindex of the selected row
var index = obj.combogrid (' grid '). DataGrid (' Getrowindex ', selected);
Move down to the last line of the page
if (Index < Obj.combogrid (' grid '). DataGrid (' GetData '). Rows.length-1) {
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', index + 1);
}
} else {
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', 0);
}
},
Enter:function () {//"enter" to defer processing

Obj.combogrid (' Hidepanel ');
},
Query:function (keyword) {//"Dynamic Search" processing
Set query parameters
var queryparams = Obj.combogrid ("Grid"). DataGrid (' Options '). Queryparams;
Queryparams.keyword = keyword;
Obj.combogrid ("Grid"). DataGrid (' Options '). Queryparams = Queryparams;
Reload
Obj.combogrid ("Grid"). DataGrid ("Reload");

Obj.combogrid ("setValue", keyword);
}
},
Mode: ' Remote ',
Fitcolumns:true
});
}

Data dictionary drop-down box foreground code

This. Setdict = function (obj, dictype) {
Obj.combogrid ({
PANELWIDTH:250,
IDfield: ' Code ',
TextField: ' Name ',
URL: '/common/entityjsonlist.ashx?_method=dict&dicttype= ' + dictype + "&tmp=" + math.random () + ' & Querytextfild=name ',
Method: ' Get ',
delay:1000,
Columns: [[
{field: ' Name ', title: ' Names ', width:100},
{field: ' Code ', title: ' Code ', width:100}
]],
Striped:true,
Editable:true,
Collapsible:false,//Can be folded
Fit:true,//Auto Size
Keyhandler: {
Up:function () {//"up key" to defer processing
Access to selected BOC
var selected = Obj.combogrid (' grid '). DataGrid (' getselected ');
if (selected) {
Get the rowindex of the selected row
var index = obj.combogrid (' grid '). DataGrid (' Getrowindex ', selected);
Move up to the first action stop
if (Index > 0) {
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', index-1);
}
} else {
var rows = Obj.combogrid (' grid '). DataGrid (' GetRows ');
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', rows.length-1);
}
},
Down:function () {//"down arrow" to defer processing
Access to selected BOC
var selected = Obj.combogrid (' grid '). DataGrid (' getselected ');
if (selected) {
Get the rowindex of the selected row
var index = obj.combogrid (' grid '). DataGrid (' Getrowindex ', selected);
Move down to the last line of the page
if (Index < Obj.combogrid (' grid '). DataGrid (' GetData '). Rows.length-1) {
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', index + 1);
}
} else {
Obj.combogrid (' Grid '). DataGrid (' SelectRow ', 0);
}
},
Enter:function () {//"enter" to defer processing
Obj.combogrid (' Hidepanel ');
},
Query:function (keyword) {//"Dynamic Search" processing
Set query parameters
var queryparams = Obj.combogrid ("Grid"). DataGrid (' Options '). Queryparams;
Queryparams.keyword = keyword;
Obj.combogrid ("Grid"). DataGrid (' Options '). Queryparams = Queryparams;
Reload
Obj.combogrid ("Grid"). DataGrid ("Reload");

Obj.combogrid ("setValue", keyword);
}
},
Mode: ' Remote ',
Fitcolumns:true
});
}

Easyui combogrid drop-down box smart input

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.