- 注册时间
- 2013-6-8
- 最后登录
- 2017-5-15
- 阅读权限
- 10
- 积分
- 374
- 精华
- 0
- 帖子
- 99
|
nbakill2 发表于 2013-7-22 10:35
不是很明白,可否给个例子.
我需要的效果是,弹出一个过滤窗口..然后我在里面同时设置多个查询条件,可以同时 ...
我做一个简单的实现,你可以参考一下
Html部分:
<div field="DocNo" width="150" headerAlign="center" allowSort="true" align="left" >编号
<input data-options="{Field:'DocNo',Match:'LK'}" name="mygridFilter" property="filter" class="mini-textbox" onvaluechanged="onFilterChanged" style="width:100%;" />
</div>
<div field="Title" width="*" headerAlign="center" allowSort="true">题名
<input data-options="{Field:'Title',Match:'LK'}" name="mygridFilter" property="filter" class="mini-textbox" onvaluechanged="onFilterChanged" style="width:100%;" />
</div>
脚本部分:
function onFilterChanged(e) {
var data = mini.getFilterData("mygridFilter");
grid.load({ key: data });
}
function mini.getFilterData(filterName,logic) {
var data = {};
var ctrs = mini.getsbyName(filterName);
var dataStr = "";
for (var i = 0; i < ctrs.length; i++) {
if (ctrs.Match == undefined || ctrs.Match == null)
ctrs.Match = "AND";
if (ctrs.Field.indexOf('|') <= 0)
dataStr += ctrs.Field + "|" + ctrs.Match + "|" + ctrs.getValue() + ",";
else {
var arrFields = ctrs.Field.split('|');
for(var j=0;j<arrFields.length;j++)
dataStr += arrFields[j] + "|" + ctrs.Match + "|" + ctrs.getValue() + ",";
}
}
if (dataStr != "")
dataStr = dataStr.substring(0, dataStr.length - 1);
if (logic == undefined || logic == null)
logic = "AND";
data["Logic"] = logic;
data["Data"] = dataStr;
return mini.encode(data);
}
数据被以 key:{Logic:"OR",Data:" FieldName|Match|FieldValue,FieldName|Match|FieldValue"} 方式发送到后台 你只要在后台解析 传递过来的数据 封装成查询条件
FieldName代表数据字段名,Match代表运算规则(LK= like,EQ代表=,UP代表>等) FieldValue代表字段的值
这个是我后台写的解析规则
/// <summary>
/// 根据匹配域,匹配方法,匹配域值取得匹配条件串
/// </summary>
/// <param name="fieldName">匹配域名称(同数据库一致)</param>
/// <param name="match">匹配方法(null=EQ)</param>
/// <param name="fieldValue">匹配域的值</param>
/// <returns>域的条件串</returns>
public string GetMatch(QueryField field)
{
string mop = string.Empty;
//fieldValue = fieldValue.Replace("'", "''");
switch (field.Match.ToUpper())
{
case "EQ":
mop = field.Name + "='" + field.Value + "'";
break;
case "UE":
mop = field.Name + "<>'" + field.Value + "'";
break;
case "GT":
mop = field.Name + ">'" + field.Value + "'";
break;
case "LT":
mop = field.Name + "<'" + field.Value + "'";
break;
case "IN":
string[] flds = field.Value.Split(',');
string fldstr = "";
for (int i = 0; i < flds.Length; i++)
fldstr += "'" + flds + "',";
fldstr = fldstr.Substring(0, fldstr.Length - 1);
mop = field.Name + " IN (" + fldstr + ")";
break;
case "FR":
mop = field.Name + ">='" + field.Value + "'";
break;
case "TO":
mop = field.Name + "<='" + field.Value + "'";
break;
case "LK":
mop = field.Name + " LIKE '%" + field.Value + "%'";
break;
case "SK":
string[] flds0 = field.Value.Split(' ');
string fldstr0 = "%";
for (int i = 0; i < flds0.Length; i++)
if (flds0.Trim() != "")
fldstr0 += flds0 + "%";
//fldstr0 = fldstr0.Substring(0,fldstr0.Length-1);
mop = field.Name + " LIKE '" + fldstr0 + "'";
break;
case "NOTNULL":
mop = field.Name + " IS NOT NULL and " + field.Name + " <>'' ";
break;
case "ISNULL":
mop = field.Name + " IS NULL or " + field.Name + " ='' ";
break;
case "OR": //支持Like运算,不支持比较符号 刘立 2005-7-14
string[] flds1 = field.Value.Split(' ');
string fldstr1 = "";
for (int i = 0; i < flds1.Length; i++)
if (flds1.Trim() != "")
fldstr1 += field.Name + " Like '%" + flds1 + "%' or ";
fldstr1 = fldstr1.Substring(0, fldstr1.Length - 3);
mop = " (" + fldstr1 + ") ";
break;
case "YEAR":
mop = string.Format(" YEAR({0}) = '{1}' ", field.Name, field.Value);
break;
case "MONTH":
mop = string.Format(" MONTH({0})='{1}' ", field.Name, field.Value);
break;
}
return mop;
}
}
|
|