jquery easyui datagrid實(shí)現(xiàn)增加,修改,刪除方法總結(jié)
本文實(shí)例講述了jquery easyui datagrid實(shí)現(xiàn)增加,修改,刪除的方法。分享給大家供大家參考,具體如下:
頁面:
<body> <form id="form1" runat="server"> <table id="tt"> </table> </form> </body>
引用的JS:
<link rel="stylesheet" type="text/css" href="/script/themes/default/easyui.css" /> <link rel="stylesheet" type="text/css" href="/script/themes/icon.css" /> <script type="text/javascript" src="/script/jquery-1.4.2.min.js" </script> <script type="text/javascript" src="/script/jquery.easyui.min.js" </script> <script type="text/javascript" src="/script/locale/easyui-lang-zh_CN.js" mce_src="script/locale/easyui-lang-zh_CN.js"></script>
JS:
<script type="text/javascript"><!--
$(function(){
$('#tt').datagrid({
width:810,
height:400,
idField:'xsbh',
url:'studentHandler.ashx',
singleSelect:true,
columns:[[
{field:'xsbh',title:'編號(hào)',width:80},
{field:'UserName',title:'姓名',width:100},
{field:'Sex',title:'性別',width:30},
{field:'SchoolYear',title:'年份',width:50},
{field:'opt',title:'操作',width:100,align:'center',
formatter:function(value,rec,index){
var s = '<a href="#" mce_href="#" onclick="view(\''+ rec.xsbh + '\')">查看</a> ';
var e = '<a href="#" mce_href="#" onclick="edit(\''+ rec.xsbh + '\')">編輯</a> ';
var d = '<a href="#" mce_href="#" onclick="del(\''+ index +'\')">刪除</a> ';
return s+e+d;
}
}
]],
toolbar:[{
text:'增加',iconCls:'icon-add',handler:function(){
window.location.href='StuAdd.aspx';
}
},
{text:'導(dǎo)入',iconCls:'icon-add',handler:function(){
window.location.href='StuImport.aspx'
}
},
{text:'查找',iconCls:'icon-search'}
],
pagination:true
});
})
function view(bh) //轉(zhuǎn)到查看頁面
{
window.location.href='StuView.aspx?id='+bh+'&page=stu';
// var row = $('#tt').datagrid('getSelected');
// if(row)
// {
// alert(row.xsbh);
// }
}
function edit(bh) //轉(zhuǎn)到編輯頁面
{
window.location.href='StuEdit.aspx?id='+bh;
}
function del(index){ //刪除操作
$.messager.confirm('確認(rèn)','確認(rèn)刪除?',function(row){
if(row){
var selectedRow = $('#tt').datagrid('getSelected'); //獲取選中行
$.ajax({
url:'delHandler.ashx?id='+selectedRow.xsbh+'&type=stu',
//加了個(gè)type,作用是以后不管什么刪除,都可以轉(zhuǎn)到這個(gè)ashx中處理
success:function(){alert('刪除成功');}
});
$('#tt').datagrid('deleteRow',index);
}
})
}
// -->
</script>
這里面要注意的是,"操作"的跨行,一定要帶上field:'opt',當(dāng)然,field可以是任何值,這個(gè)值不用從數(shù)據(jù)庫(kù)中綁定,隨便取.如果沒有field的話,會(huì)彈出 "rowspan為空或不是對(duì)象"的錯(cuò)誤
獲取數(shù)據(jù)和分頁ashx:
using System;
using System.Web;
using System.Data;
using System.Text;
public class studentHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
DataSet ds = new DataSet();
//點(diǎn)擊datagrid的分頁按鈕,自動(dòng)向后臺(tái)發(fā)送2個(gè)參數(shù),rows和page,代表每頁記錄數(shù)和頁索引
int row = int.Parse(context.Request["rows"].ToString());
int page = int.Parse(context.Request["page"].ToString());
ds = GetContent(row, page);
string text =json.Dataset2Json(ds);
context.Response.Write(text);
}
private DataSet GetContent(int pagesize,int pageindex)
{
Graduate.BLL.Student bll = new Graduate.BLL.Student();
return bll.GetList(pagesize, pageindex);
}
public bool IsReusable {
get {
return false;
}
}
}
刪除ashx
using System;
using System.Web;
using System.Web.SessionState;
public class delHandler : IHttpHandler,IRequiresSessionState {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string id = context.Request["id"].ToString();
string type = context.Request["type"].ToString();
switch (type)
{
case "stu":
Graduate.BLL.Student stubll = new Graduate.BLL.Student();
stubll.Delete(id, HttpContext.Current.Session["username"].ToString(), HttpContext.Current.Session["usertype"].ToString());
break;
default:
break;
}
}
public bool IsReusable {
get {
return false;
}
}
}
IRequiresSessionState 是因?yàn)橛玫搅朔?wù)器端的session,沒有用到的話可以去掉
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》、《jquery選擇器用法總結(jié)》及《jQuery常用插件及用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jquery Easyui Datagrid實(shí)現(xiàn)批量操作(編輯,刪除,添加)
- jQuery Easyui datagrid連續(xù)發(fā)送兩次請(qǐng)求問題
- easyui datagrid 大數(shù)據(jù)加載效率慢,優(yōu)化解決方法(推薦)
- jQuery EasyUI編輯DataGrid用combobox實(shí)現(xiàn)多級(jí)聯(lián)動(dòng)
- jQuery Easyui DataGrid點(diǎn)擊某個(gè)單元格即進(jìn)入編輯狀態(tài)焦點(diǎn)移開后保存數(shù)據(jù)
- jQuery EasyUI學(xué)習(xí)教程之datagrid點(diǎn)擊列表頭排序
- jQuery Easyui學(xué)習(xí)教程之實(shí)現(xiàn)datagrid在沒有數(shù)據(jù)時(shí)顯示相關(guān)提示內(nèi)容
- jQuery EasyUI框架中的Datagrid數(shù)據(jù)表格組件結(jié)構(gòu)詳解
- jQuery easyUI datagrid 增加求和統(tǒng)計(jì)行的實(shí)現(xiàn)代碼
- 簡(jiǎn)介EasyUI datagrid editor combogrid搜索框的實(shí)現(xiàn)
- 詳解EasyUi控件中的Datagrid
相關(guān)文章
jQuery簡(jiǎn)單實(shí)現(xiàn)遍歷數(shù)組的方法
這篇文章主要介紹了jQuery簡(jiǎn)單實(shí)現(xiàn)遍歷數(shù)組的方法,涉及jQuery遍歷數(shù)組的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
jQuery插件擴(kuò)展extend的簡(jiǎn)單實(shí)現(xiàn)原理
下面小編就為大家?guī)硪黄猨Query插件擴(kuò)展extend的簡(jiǎn)單實(shí)現(xiàn)原理。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06
jquery實(shí)現(xiàn)Ctrl+Enter提交表單的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)Ctrl+Enter提交表單的方法,涉及jquery針對(duì)鍵盤按鍵的響應(yīng)與表單操作相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-07-07
jQuery中的$是什么意思及 $. 和 $().的區(qū)別
這篇文章主要介紹了jQuery中的$是什么意思及 $. 和 $().的區(qū)別,需要的朋友可以參考下2018-04-04
Jquery下的26個(gè)實(shí)用小技巧(jQuery tips, tricks & solutions)
前段時(shí)間發(fā)布了Jquery類庫(kù)1.4版本,使用者也越來越多,為了方便大家對(duì)Jquery的使用,下面列出了一些Jquery使用技巧。2010-03-03
BootStrap的table表頭固定tbody滾動(dòng)的實(shí)例代碼
本文給大家分享一段關(guān)于BootStrap的table表頭固定tbody滾動(dòng)的實(shí)例代碼,代碼簡(jiǎn)單易懂,需要的朋友可以參考下2016-08-08
關(guān)于jQuery EasyUI 中刷新Tab選項(xiàng)卡后一個(gè)頁面變形的解決方法
這篇文章主要介紹了關(guān)于jQuery EasyUI 中刷新Tab選項(xiàng)卡后一個(gè)頁面變形的解決方法,需要的朋友可以參考下2017-03-03
jQuery實(shí)現(xiàn)文本顯示一段時(shí)間后隱藏的方法分析
這篇文章主要介紹了jQuery實(shí)現(xiàn)文本顯示一段時(shí)間后隱藏的方法,結(jié)合實(shí)例形式分析了jQuery事件響應(yīng)及頁面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-06-06

