今天在开发一个功能时候,需要直接在列表实现新增、编辑等功能。于是查看easyui 相关文档,找到相关解决办法。
easyui的datagrid支持可编辑功能。它使用户能够向数据网格中添加一个新行。用户也可以更新一个或多个行。
下面是我在项目中的实现代码:
第一步:引用
      easyui.css
第二步:Html和Javascript代码
    <h2>Editable DataGrid Demo</h2>
<div class="demo-info">
<div class="demo-tip icon-tip">&nbsp;</div>
<div>Click the edit button on the right side of row to start editing.</div>
</div> <div style="margin:10px 0">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="insert()">Insert Row</a>
</div> <table id="tt"></table> <script>
var products = [
{productid:'FI-SW-01',name:'Koi'},
{productid:'K9-DL-01',name:'Dalmation'},
{productid:'RP-SN-01',name:'Rattlesnake'},
{productid:'RP-LI-02',name:'Iguana'},
{productid:'FL-DSH-01',name:'Manx'},
{productid:'FL-DLH-02',name:'Persian'},
{productid:'AV-CB-01',name:'Amazon Parrot'}
];
$(function(){
$('#tt').datagrid({
title:'Editable DataGrid',
iconCls:'icon-edit',
width:660,
height:250,
singleSelect:true,
idField:'itemid',
url:'data/datagrid_data.json',
columns:[[
{field:'itemid',title:'Item ID',width:60},
{field:'productid',title:'Product',width:100,
formatter:function(value,row){
return row.productname || value;
},
editor:{
type:'combobox',
options:{
valueField:'productid',
textField:'name',
data:products,
required:true
}
}
},
{field:'listprice',title:'List Price',width:80,align:'right',editor:{type:'numberbox',options:{precision:1}}},
{field:'unitcost',title:'Unit Cost',width:80,align:'right',editor:'numberbox'},
{field:'attr1',title:'Attribute',width:180,editor:'text'},
{field:'status',title:'Status',width:50,align:'center',
editor:{
type:'checkbox',
options:{
on: 'P',
off: ''
}
}
},
{field:'action',title:'Action',width:80,align:'center',
formatter:function(value,row,index){
if (row.editing){
var s = '<a href="javascript:void(0)" onclick="saverow(this)">Save</a> ';
var c = '<a href="javascript:void(0)" onclick="cancelrow(this)">Cancel</a>';
return s+c;
} else {
var e = '<a href="javascript:void(0)" onclick="editrow(this)">Edit</a> ';
var d = '<a href="javascript:void(0)" onclick="deleterow(this)">Delete</a>';
return e+d;
}
}
}
]],
onEndEdit:function(index,row){
var ed = $(this).datagrid('getEditor', {
index: index,
field: 'productid'
});
row.productname = $(ed.target).combobox('getText');
},
onBeforeEdit:function(index,row){
row.editing = true;
$(this).datagrid('refreshRow', index);
},
onAfterEdit:function(index,row){
row.editing = false;
$(this).datagrid('refreshRow', index);
},
onCancelEdit:function(index,row){
row.editing = false;
$(this).datagrid('refreshRow', index);
}
});
});
function getRowIndex(target){
var tr = $(target).closest('tr.datagrid-row');
return parseInt(tr.attr('datagrid-row-index'));
}
function editrow(target){
$('#tt').datagrid('beginEdit', getRowIndex(target));
}
function deleterow(target){
$.messager.confirm('Confirm','Are you sure?',function(r){
if (r){
$('#tt').datagrid('deleteRow', getRowIndex(target));
}
});
}
function saverow(target){
$('#tt').datagrid('endEdit', getRowIndex(target));
}
function cancelrow(target){
$('#tt').datagrid('cancelEdit', getRowIndex(target));
}
function insert(){
var row = $('#tt').datagrid('getSelected');
if (row){
var index = $('#tt').datagrid('getRowIndex', row);
} else {
index = 0;
}
$('#tt').datagrid('insertRow', {
index: index,
row:{
status:'P'
}
});
$('#tt').datagrid('selectRow',index);
$('#tt').datagrid('beginEdit',index);
}
</script>

希望可以帮到有类似需求的朋友。

 
      

Editable DataGrid 实现列表新增编辑功能的更多相关文章

  1. atitit.新增编辑功能 跟orm的实现 attilax p31

    atitit.新增编辑功能 跟orm的实现 attilax p31 1. 流程的实现 1 2. view的实现(dwr) 1 3. 获取表结构 1 4. grep filt req params 2 ...

  2. easyui datagrid 行编辑功能

    datagrid现在具有行编辑能力了,使用时只须在columns中为需要编辑的列添加一个editor属性,编辑保存时同时具有数据校验能力. 看一个例子效果图: 代码如下: $('#tt').datag ...

  3. ABBYY FineReader 15 新增编辑表格单元格功能

    ABBYY FineReader 15(Windows系统)新增编辑表格单元格功能,在PDF文档存在表格的前提下,可将表中的每个单元格作为单独的文字块进行单独编辑,单元格内的编辑不会影响同一行中其他单 ...

  4. EasyUI的datagrid获取所有正在编辑状态的行的行编号

    今天项目需要用了下EasyUI的datagrid的行编辑功能,跟着API来,只要是将各种状态时的处理逻辑弄好,还是蛮不错的. 开发过程中,遇到了个问题,在编辑完成后我需要获取datagrid所有处于编 ...

  5. jquery-easyui 中表格的行编辑功能

    具体实现代码如下: <table id="tt"></table> $('#tt').datagrid({ title:'Editable DataGrid ...

  6. Web界面开发必看!Kendo UI for jQuery编辑功能指南第一弹

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  7. salesforce 零基础学习(四十四)实现checkbox列表简单过滤功能

    现在做的项目代码是原来其他公司做的,要在原来基础上业务进行适当调整加上一些CR,其中有一个需要调整的需求如下: 原来使用apex:selectCheckboxes封装了一个checkbox列表,因为数 ...

  8. c# 框架学习(nop )总结-------编辑功能

    一.在js中配置列: <script> $(document).ready(function () { $("#enterprise-grid").kendoGrid( ...

  9. jquery-easyui中表格的行编辑功能

    datagrid现在具有行编辑能力了,使用时只须在columns中为需要编辑的列添加一个editor属性,编辑保存时同时具有数据校验能力. 看一个例子效果图: 代码如下: $('#tt').datag ...

随机推荐

  1. AC自动机最好讲解

    http://www.cs.uku.fi/~kilpelai/BSA05/lectures/slides04.pdf

  2. Windows Store App 近期访问列表

    Windows 8系统在管理用户的文件时,会将用户近期访问的文件添加到对应应用的近期访问列表中,所有的Windows应用商店应用都有各自的近期访问列表,根据文件的上一次访问时间,可以在列表中对文件进行 ...

  3. position 定位

    position属性是指本体相对于上级的定位,position又分绝对定位和相对定位.他的默认值是static,意味着元素没有被定位,出现在文档流中应该出现的位置.如果用position来布局页面,父 ...

  4. [html5]placeholder默认颜色

    :-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #f00; } ::-moz-placeholder { /* Mozilla Fir ...

  5. 在 Apache error_log 中看到多个信息,提示 RSA server certificate CommonName (CN) 与服务器名不匹配(转)

    在 Apache error_log 中看到多个信息,提示 RSA server certificate CommonName (CN) 与服务器名不匹配. Article ID: 1500, cre ...

  6. iOS去除导航栏和tabbar的横线

    导航[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetri ...

  7. 分析器错误 MvcApplication 找不到

    <%@ Application Codebehind="Global.asax.cs" Inherits="test.MvcApplication" La ...

  8. LPTHW 笨方法学python 19章

    本章节,我只是把所有的输出加上了自己的注释. #!/usr/bin/env python # -*- coding:utf-8 -*- def cheese_and_crakers(cheese_co ...

  9. 详解Objective-C runtime

    感谢翻译小组成员wingpan热心翻译.本篇文章是我们每周推荐优秀国外的技术类文章的其中一篇.如果您有不错的原创或译文,欢迎提交给我们,更欢迎其他朋友加入我们的翻译小组(联系qq:2408167315 ...

  10. C语言处理xml文件的库

    读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好. TinyXML是一个开源的解 ...