$.fn.extend({ SetDict: function (option) { var txtControl = $(this); if (!txtControl.hasClass("combo-text")) { // var width = txtControl.width(); //txtControl.addClass("combo"); } txtControl.click(function () { var obj = option.valueControl; var dicType = option.dicType; var isShow = txtControl.attr("isShow"); if (isShow == null || isShow == "") { txtControl.attr("isShow", "1"); txtControl.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: ‘名称‘, width: 100 }, { field: ‘Code‘, title: ‘编码‘, width: 100 } ]], striped: true, editable: true, collapsible: false, //是否可折叠的 fit: true, onLoadSuccess: function () { window.setTimeout(function () { $(".combo-arrow", option.valueControl.parent()).click(); }, 100); }, onClickRow: function (index, row) { txtControl.val(row.Name); option.valueControl.val(row.Code); }, //自动大小 keyHandler: { up: function () { //【向上键】押下处理 //取得选中行 var selected = txtControl.combogrid(‘grid‘).datagrid(‘getSelected‘); if (selected) { //取得选中行的rowIndex var index = txtControl.combogrid(‘grid‘).datagrid(‘getRowIndex‘, selected); txtControl.val(selected.Name); option.valueControl.val(selected.Code); //向上移动到第一行为止 if (index > 0) { txtControl.combogrid(‘grid‘).datagrid(‘selectRow‘, index - 1); } } else { var rows = txtControl.combogrid(‘grid‘).datagrid(‘getRows‘); txtControl.combogrid(‘grid‘).datagrid(‘selectRow‘, rows.length - 1); } }, down: function () { //【向下键】押下处理 //取得选中行 var selected = txtControl.combogrid(‘grid‘).datagrid(‘getSelected‘); if (selected) { txtControl.val(selected.Name); option.valueControl.val(selected.Code); //取得选中行的rowIndex var index = txtControl.combogrid(‘grid‘).datagrid(‘getRowIndex‘, selected); //向下移动到当页最后一行为止 if (index < txtControl.combogrid(‘grid‘).datagrid(‘getData‘).rows.length - 1) { txtControl.combogrid(‘grid‘).datagrid(‘selectRow‘, index + 1); } } else { txtControl.combogrid(‘grid‘).datagrid(‘selectRow‘, 0); } }, enter: function () { //【回车键】押下处理 txtControl.combogrid(‘hidePanel‘); var selected = txtControl.combogrid(‘grid‘).datagrid(‘getSelected‘); if (selected) { txtControl.val(selected.Name); option.valueControl.val(selected.Code); } }, query: function (keyword) { //【动态搜索】处理 //设置查询参数 var queryParams = txtControl.combogrid("grid").datagrid(‘options‘).queryParams; queryParams.keyword = keyword; txtControl.combogrid("grid").datagrid(‘options‘).queryParams = queryParams; //重新加载 txtControl.combogrid("grid").datagrid("reload"); txtControl.combogrid("setValue", keyword); } }, mode: ‘remote‘, fitColumns: true }); } }); } }); $.fn.extend({ SetCombo: function (option) {/// <reference path="../Common/JGridJson.cs" /> var entityType = option.entityType; var textField = option.textField; var textControl = $(this); var panelWidth = option.panelWidth; var idFild = option.idFild; var valueControl = option.valueControl; var panelHeight = option.panelHeight; var columns = option.columns; var where = option.where; //var keyword = option.keyword; var pageSize = option.pageSize; if (option.pageSize == null) { pageSize = 10; } var obj = valueControl; if (panelHeight == null) { panelHeight = 300; } var url = ‘/common/EntityJsonList.ashx?entityType=‘ + option.entityType + ‘&_method=entity&tmp=‘ + Math.random() + ‘&queryTextFild=‘ + textField; if (where) { url += "&where=" + where; } if (panelWidth == null) { panelWidth = 500; } if (valueControl.val() != "") { url += "&defaultValue=" + escape(valueControl.val()); } var id = ‘Id‘; if (idFild != null) { id = idFild; } url += "&idFild=" + id; textControl.click(function () { var a = textControl.attr("isShow"); if (a == "" || a == null) { textControl.attr("isShow", "1"); textControl.combogrid({ panelWidth: panelWidth, panelHeight: panelHeight, idField: id, textField: textField, url: url, method: ‘get‘, delay: 1000, pagination: true, //是否分页 rownumbers: true, //序号 pageSize: pageSize, //每页显示的记录条数,默认为10 pageList: [pageSize, 10, 20, 30, 40, 50, 100, 200], //可以设置每页记录条数的列表 columns: columns, striped: true, editable: true, collapsible: false, //是否可折叠的 fit: true, onLoadSuccess: function () { window.setTimeout(function () { $(".combo-arrow", option.valueControl.parent()).click(); }, 100); }, onClickRow: function (index, row) { valueControl.val(UTIL.getJsonByKey(row, idFild)); textControl.val(UTIL.getJsonByKey(row, textField)); }, //自 keyHandler: { up: function () { //【向上键】押下处理 //取得选中行 var selected = textControl.combogrid(‘grid‘).datagrid(‘getSelected‘); if (selected) { //取得选中行的rowIndex = txtControlex var index = combogrid(‘grid‘).datagrid(‘getRowIndex‘, selected); valueControl.val(UTIL.getJsonByKey(selected, idFild)); textControl.val(UTIL.getJsonByKey(selected, textField)); //向上移动到第一行为止 if (index > 0) { textControl.combogrid(‘grid‘).datagrid(‘selectRow‘, index - 1); } } else { var rows = textControl.combogrid(‘grid‘).datagrid(‘getRows‘); textControl.combogrid(‘grid‘).datagrid(‘selectRow‘, rows.length - 1); } }, down: function () { //【向下键】押下处理 //取得选中行 var selected = textControl.combogrid(‘grid‘).datagrid(‘getSelected‘); if (selected) { valueControl.val(UTIL.getJsonByKey(selected, idFild)); textControl.val(UTIL.getJsonByKey(selected, textField)); //取得选中行的rowIndex var index = textControl.combogrid(‘grid‘).datagrid(‘getRowIndex‘, selected); //向下移动到当页最后一行为止 if (index < textControl.combogrid(‘grid‘).datagrid(‘getData‘).rows.length - 1) { textControl.combogrid(‘grid‘).datagrid(‘selectRow‘, index + 1); } } else { textControl.combogrid(‘grid‘).datagrid(‘selectRow‘, 0); } }, enter: function () { //【回车键】押下处理 textControl.combogrid(‘hidePanel‘); var selected = textControl.combogrid(‘grid‘).datagrid(‘getSelected‘); if (selected) { valueControl.val(UTIL.getJsonByKey(selected, idFild)); textControl.val(UTIL.getJsonByKey(selected, textField)); } }, query: function (keyword) { //【动态搜索】处理 //设置查询参数 var queryParams = textControl.combogrid("grid").datagrid(‘options‘).queryParams; queryParams.keyword = keyword; textControl.combogrid("grid").datagrid(‘options‘).queryParams = queryParams; //重新加载 textControl.combogrid("grid").datagrid("reload"); textControl.combogrid("setValue", keyword); } }, mode: ‘remote‘, fitColumns: true }); } }); } });
时间: 2024-10-10 21:53:29