Flexigrid例子二: 原位编辑器

本文介绍如何在Flexigrid中实现原位编辑功能,利用jquery-in-place-editor库,无需弹出对话框即可编辑表格数据。编辑操作通过Ajax发送到服务器的update_description接口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有时候,我们想要编辑flexigrid里的数据。一个原位编辑器是需要的,现在不需要再弹出一个对话框了。这里我会展示如何做到这点。

我使用了jquery-in-place-editor库。请参考官方站点:http://code.google.com/p/jquery-in-place-editor/

step1: 在定义flexigrid模型的时候,添加一个函数来处理flexigrid的列

$(document).ready ( function() {
    $("#displays").flexigrid (
 {
     url: '<%=jsonp%>/bindedDisplays',
     method:'POST',
     dataType: 'json',
     width: 400,
     height: 300,
     colModel : [
  {hide: '<%=check%>', name: 'check', width: 30, sortable: true, align: 'left'},
  {display: 'ID', name: 'id', width: 90, sortable: true, align: 'left'},
  {display: '<%=description%>', name: 'description', width: 110, sortable: true, align: 'left',process:editDescription},
  {display: '<%=status%>', name: 'status', width: 20, sortable: true, align: 'left'},
  {display: '<%=unbind%>', name: 'unbind', width: 20, sortable: true, align: 'left',process:unbindDisplay}
     ]
 }
    ); 
}
    );

step2: 使用jquery-in-place-editor来实现editDescription函数

function editDescription(celDiv, id){
    $( celDiv ).click( function() {
 var idTd = $(celDiv).parent().parent().children()[1];
 $(celDiv).editInPlace({
     url: "update_description",
     params: "address="+$(idTd.children).html(),
     error:function(obj){
  alert(JSON.stringify(obj));
     },
     success:function(obj){
  var str = m[JSON.parse(obj).status+""][window.curLanguage];
  alert(str);
  $("#displays").flexReload();
     }
 });
    });
}

$(celDiv).editInPlace 会让你在web界面上看到原位编辑的效果。

Ajax请求会通过jquery-in-place-editor发到web server的update_description路径上。

非常简单,你当然也需要引入必要的js文件,像这样:

<script type="text/javascript" src="script/jquery.editinplace.js"></script>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值