easyUI datagrid简单使用:着重两点1、editor对象的click事件;2、将dialog窗体内的值填写到当前正编辑的单元格内

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/easyui.css" rel="stylesheet" />
<link href="css/icon.css" rel="stylesheet" />
<link href="css/demo.css" rel="stylesheet" />
<script src="js/jquery.min.js"></script>
<script src="js/jquery.easyui.min.js"></script>
</head>
<body>
<!--datagrid-->
<table id="dg"></table>
<!--dialog-->
<div id="dd">
<input type="text" id="txt" />
</div>
<script type="text/javascript">
var columns = [[
{ field: 'A', title: 'A', width: 100, rowspan: 2 },
{ title: 'B', colspan: 3 },
{ title: 'C', colspan: 3 }
], [
{
field: 'a', title: 'a', width: 100, editor: {
type: 'textbox',
options: {
required: true,
missingMessage: '*必填*'
}
}
},
{
field: 'b', title: 'b', width: 100, editor: {
type: 'datebox'
}
},
{
field: 'c', title: 'c', width: 100, editor: {
type: 'combobox',
options: {
data: [{ value: 'cc', text: 'cc' }, { value: 'ccc', text: 'ccc' }],
panelHeight: 'auto'
}
}
},
{
field: 'd', title: 'd', width: 100, editor: {
type: 'numberbox',
options: { precision: 1 }
}
},
{ field: 'e', title: 'e', width: 100, editor: { type: 'checkbox', options: { on: '1', off: '0' } } },
{
field: 'f', title: 'f', width: 100, editor: {
type: 'dialog',
options: {
dlgId: 'dd',
textId: 'txt',
currField: 'f'
}
}
}
]];
var data = [{ A: 'A', a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f' }];
$(function () {
//初始化弹窗
$('#dd').dialog({
title: '弹窗',
width: 400,
height: 'auto',
closed: true,
cache: false,
modal: true,
buttons: [{
text: '保存',
handler: function () {
var index = editIndex;
var cellEditor = $('#dg').datagrid('getEditor', { index: index, field: editField });
cellEditor.actions.setValue(cellEditor.target, $('#txt').val());
$('#dd').dialog('close');
}
}, {
text: '取消',
handler: function () {
$('#dd').dialog('close');
}
}]
});
//初始化表格
$('#dg').datagrid({
data: data,
title: '对账报告- PA02',
iconCls: 'icon-title',
width: 650,
height: 'auto',
singleSelect: true,
fitColumns: false,
columns: columns,
rownumbers: true,
showFooter: true,
pagination: true,//分页控件
fit: true,//自动大小
border: true,
onLoadSuccess: onLoadSuccess,
toolbar: [{
text: '添加',
iconCls: 'icon-add',
handler: function () {
editCell = false;
if ($('#dg').datagrid('validateRow', editIndex)) {
$('#dg').datagrid('endEdit', editIndex);
$('#dg').datagrid('appendRow', {});
$('#dg').datagrid('selectRow', editIndex + 1).datagrid('beginEdit', editIndex + 1);
editIndex = editIndex + 1;
}
}
}]
});
//设置分页控件
var p = $('#dg').datagrid('getPager');
$(p).pagination({
pageSize: 10,//每页显示的记录条数,默认为10
pageList: [5, 10, 15],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
showRefresh: false,
afterPageText: '页 共 {pages} 页',
displayMsg: '<span style="font-size:20px;font-weight:700"></span>当前显示 {from} - {to} 条记录 共 {total} 条记录'
});
});
var editIndex = -1;//标识编辑行
var editField;//正在编辑的单元格所属字段
function onLoadSuccess() {
editIndex = $('#dg').datagrid('getRows').length - 1;
}
//重写editor,添加弹出框类型
$.extend($.fn.datagrid.defaults.editors, {
dialog: {
init: function (container, options) {
var editor = $('<input type="text"/>').appendTo(container);
editor.textbox(options);
container.click(function () {
$('#' + options['dlgId']).dialog('open');
editField = options['currField'];
});
return editor;
},
getValue: function (target) {
return $(target).textbox('getValue', $(target).val());
},
setValue: function (target, value) {
if (value)
$(target).textbox('setValue', value);
else
$(target).textbox('setValue', '');
},
resize: function (target, width) {
$(target).textbox('resize', width);
},
destroy: function (target) {
$(target).textbox('destroy');
}
}
});
</script>
</body>
</html>

easyUI datagrid

页码导航栏pagination,在此处代码中与datagrid分开初始化,自定义了pagination,会导致初始页面加载两次,其原因是第一次表格加载取得总记录数total,和页码栏total值不相等,那么easyui会重新发一次请求,解决办法是可以注释掉源码中再次请求的代码

1097//if(_b3.total==0){
1098//_b3.pageNumber=0;
1099//_b4=0;
1100//}

但是还有解决办法,注释掉下面代码,没有测试呢

if(_615.total!=data.total){
_614.pagination("refresh",{total:data.total});
if(opts.pageNumber!=_615.pageNumber){
opts.pageNumber=_615.pageNumber;
_5d7(_60f);
}
}

easyUI datagrid editor扩展dialog的更多相关文章

  1. 关于EasyUI datagrid editor combogrid搜索框的实现

    首先需要datagrid editor对combogrid的扩展,这个是别人实现的: $.extend($.fn.datagrid.defaults.editors, { combogrid: { i ...

  2. easyui datagrid editor checkbox 单击事件

    Easyui datagrid treegrid中能够为行追加checkbox元素.比如: $('#tt').treegrid({ url:'get_data.php', idField:'id', ...

  3. jquery EasyUI datagrid 的扩展

    接触 easyui 半年,js学的不深.大神请路过. 直接扩展 添加方法: $.extend($.fn.datagrid.methods, { getSelectedIndex: function ( ...

  4. easyui datagrid plunges 扩展 插件

      项目使用 springmvc4.x  spring4.x  hibernate4.x easyui 为了便于开发,扩展了easyui 的 datagrid 功能,下面直接贴上扩展代码: /** * ...

  5. 关于EasyUI datagrid 无法在dialog中显示的问题分析及解决方案!

    最近项目中引用了easyUI,很大程度上的简化了开发过程,但是随之而来的也遇到一些问题,比如:标题中遇到的问题,去网上搜罗了下关于这个问题的解决方案,不是说的很复杂就是干脆文不对题,国外的使用这种稍微 ...

  6. Easyui datagrid editor为combobox时指定数据源

    当在datagrid行内部应用添加编辑操作时,引入combobox是非常方便的操作,我在引入combobox时对数据源这快做个总结,在做demo的过程中遇到个问题,就是当你选择了下拉框的值后点击保存, ...

  7. easyUI datagrid view扩展

    //扩展easyuidatagrid无数据时显示界面 var emptyView = $.extend({}, $.fn.datagrid.defaults.view, { onAfterRender ...

  8. easyui datagrid editor combobox添加空选则清空combobox框

    <script type='text/javascript'> var editIndex = undefined; $(function() { $('#tb1').datagrid({ ...

  9. easyui datagrid editor onBeforeEdit事件下使用getEditor和getEditors失效

    我在使用onClickRow: function(rowIndex,rowData){                    if(editRow!=-1){                      ...

随机推荐

  1. mvc的自带json序列化的datetime在js中的解析

    默认仅序列化后的日期格式是这样的:'/Date(124565787989)/'(数字随便敲的,数字表示相对于1970年的总毫秒数) 在js中借助eval函数,eval函数的意义:将参数中的字符串当作j ...

  2. Maven遇到的错误汇总

    使用工具是MyEclipse10: 1.创建Maven项目出错 1.项目名带有Maven Webapp 解决方案: 2.缺少jar could not resolve archetype :   Co ...

  3. [Mindjet MindManager]思维导图的快捷键操作

    来源于:http://www.cnblogs.com/whylaughing/p/5530935.html Mindjet MindManager(思维导图) 快捷键如下: Insert or CTR ...

  4. 开发错误记录8:Unable to instantiate application com

    开发错误记录8:Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication 这是因为在And ...

  5. git log 格式化输出

    Git log --graph --pretty=format: '%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)& ...

  6. WPF 资源字典【转】

    使用好处:存储需要被本地话的内容(错误消息字符串等,实现软编码),减少重复的代码,重用样式,实现多个项目之间的共享资源;修改一个地方所有引用的地方都会被修改,方便统一风格;使用方法,归纳起来主要有下面 ...

  7. lucene-查询query->RangeQuery在某一范围内搜索

    有时用户会需要一种在一个范围内查找某个文档,比如查找某一时间段内的所有文档,此时,Lucene提供了一种名为RangeQuery的类来满足这种需求. RangeQuery表示在某范围内的搜索条件,实现 ...

  8. 【Codeforces 723C】Polycarp at the Radio 贪心

    n个数,用最少的次数来改变数字,使得1到m出现的次数的最小值最大.输出最小值和改变次数以及改变后的数组. 最小值最大一定是n/m,然后把可以改变的位置上的数变为需要的数. http://codefor ...

  9. HDU 1754 I Hate It

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. 浅析C# new和override的区别

    C#中new和override是继承中经常用到的两个关键字,但是往往有时候容易把这两个关键字的作用搞混淆. new C# new关键字表示隐藏,是指加上new关键字的属性或函数将对本类和继承类隐藏基类 ...