jQuery EasyUI编辑DataGrid用combobox实现多级联动
我在项目中设计课程表的时候需要用到老师和分类之间的多级联动。
首先是一张效果图:
下面是实现的代码:
<body>
<script type=
"text/javascript"
>
$(
function
(){
var
editing ;
//判断用户是否处于编辑状态
var
flag ;
//判断新增和修改方法
$(
'#set_schedule'
).datagrid({
idField:
'id'
,
fitColumns:
false
,
url:
'scheduleAction_loadScheduleData.action?sureDocumentId='
+$(
"#sureDocumentId"
).val() ,
striped:
true
,
loadMsg:
'数据正在加载,请耐心的等待...'
,
rownumbers:
true
,
singleSelect :
true
,
frozenColumns:[[
{field:
'ck'
, checkbox:
true
}
]],
columns:[[
{
field:
'dateTime'
,
title:
'时间'
,
width:100 ,
align:
'center'
,
editor:{
type:
'datebox'
,
options:{
required:
true
,
missingMessage:
'时间必填!'
,
editable:
false
}
}
},
{
field:
'morningTime'
,
title:
'上午上课时间段'
,
width:126 ,
align:
'center'
,
editor:{
type:
'validatebox'
,
options:{
required:
true
,
missingMessage:
'时间段必填!'
}
}
},
{
field:
'morningCourse'
,
title:
'上午课程'
,
width:100 ,
editor:{
type:
'validatebox'
,
options:{
required:
true
,
missingMessage:
'课程必填!'
}
}
},
{
field:
'aa1'
,
title:
'主讲老师分类'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'codeTypeAction_search.action?parentId=0&type=27'
,
valueField:
'id'
,
textField:
'name'
,
onSelect:
function
(data){
var
row = $(
'#set_schedule'
).datagrid(
'getSelected'
);
var
rowIndex = $(
'#set_schedule'
).datagrid(
'getRowIndex'
,row);
//获取行号
var
thisTarget = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'aa1'
}).target;
var
value = thisTarget.combobox(
'getValue'
);
var
target = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'bb1'
}).target;
target.combobox(
'clear'
);
//清除原来的数据
var
url =
'codeTypeAction_search.action?type=28&parentId='
+value;
target.combobox(
'reload'
, url);
//联动下拉列表重载
}
}
}
},
{
field:
'bb1'
,
title:
'主讲老师细类'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'codeTypeAction_search.action?type=28'
,
valueField:
'id'
,
textField:
'name'
,
onSelect:
function
(data){
var
row = $(
'#set_schedule'
).datagrid(
'getSelected'
);
var
rowIndex = $(
'#set_schedule'
).datagrid(
'getRowIndex'
,row);
//获取行号
var
thisTarget = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'bb1'
}).target;
var
value = thisTarget.combobox(
'getValue'
);
var
target = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'morningTeacherId'
}).target;
target.combobox(
'clear'
);
//清除原来的数据
var
url =
'teacherAction_search.action?teacherTypeId2='
+value;
target.combobox(
'reload'
, url);
//联动下拉列表重载
}
}
}
},
{
field:
'morningTeacherId'
,
title:
'主讲老师'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'teacherAction_search.action'
,
valueField:
'id'
,
textField:
'name'
}
}
},
{
field:
'afternoonTime'
,
title:
'下午上课时间段'
,
width:126 ,
align:
'center'
,
editor:{
type:
'validatebox'
,
options:{
required:
true
,
missingMessage:
'时间段必填!'
}
}
},
{
field:
'afternoonCourse'
,
title:
'下午课程'
,
width:100 ,
editor:{
type:
'validatebox'
,
options:{
required:
true
,
missingMessage:
'课程必填!'
}
}
},
{
field:
'aa2'
,
title:
'主讲老师分类'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'codeTypeAction_search.action?parentId=0&type=27'
,
valueField:
'id'
,
textField:
'name'
,
onSelect:
function
(data){
var
row = $(
'#set_schedule'
).datagrid(
'getSelected'
);
var
rowIndex = $(
'#set_schedule'
).datagrid(
'getRowIndex'
,row);
//获取行号
var
thisTarget = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'aa2'
}).target;
var
value = thisTarget.combobox(
'getValue'
);
var
target = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'bb2'
}).target;
target.combobox(
'clear'
);
//清除原来的数据
var
url =
'codeTypeAction_search.action?type=28&parentId='
+value;
target.combobox(
'reload'
, url);
//联动下拉列表重载
}
}
}
},
{
field:
'bb2'
,
title:
'主讲老师细类'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'codeTypeAction_search.action?type=28'
,
valueField:
'id'
,
textField:
'name'
,
onSelect:
function
(data){
var
row = $(
'#set_schedule'
).datagrid(
'getSelected'
);
var
rowIndex = $(
'#set_schedule'
).datagrid(
'getRowIndex'
,row);
//获取行号
var
thisTarget = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'bb2'
}).target;
var
value = thisTarget.combobox(
'getValue'
);
var
target = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'afternoonTeacherId'
}).target;
target.combobox(
'clear'
);
//清除原来的数据
var
url =
'teacherAction_search.action?teacherTypeId2='
+value;
target.combobox(
'reload'
, url);
//联动下拉列表重载
}
}
}
},
{
field:
'afternoonTeacherId'
,
title:
'主讲老师'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'teacherAction_search.action'
,
valueField:
'id'
,
textField:
'name'
}
}
},
{
field:
'eveningTime'
,
title:
'晚上上课时间段'
,
width:126 ,
align:
'center'
,
editor:{
type:
'validatebox'
,
options:{
required:
true
,
missingMessage:
'时间段必填!'
}
}
},
{
field:
'eveningCourse'
,
title:
'晚上课程'
,
width:100 ,
editor:{
type:
'validatebox'
,
options:{
required:
true
,
missingMessage:
'课程必填!'
}
}
},
{
field:
'aa3'
,
title:
'主讲老师分类'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'codeTypeAction_search.action?parentId=0&type=27'
,
valueField:
'id'
,
textField:
'name'
,
onSelect:
function
(data){
var
row = $(
'#set_schedule'
).datagrid(
'getSelected'
);
var
rowIndex = $(
'#set_schedule'
).datagrid(
'getRowIndex'
,row);
//获取行号
var
thisTarget = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'aa3'
}).target;
var
value = thisTarget.combobox(
'getValue'
);
var
target = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'bb3'
}).target;
target.combobox(
'clear'
);
//清除原来的数据
var
url =
'codeTypeAction_search.action?type=28&parentId='
+value;
target.combobox(
'reload'
, url);
//联动下拉列表重载
}
}
}
},
{
field:
'bb3'
,
title:
'主讲老师细类'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'codeTypeAction_search.action?type=28'
,
valueField:
'id'
,
textField:
'name'
,
onSelect:
function
(data){
var
row = $(
'#set_schedule'
).datagrid(
'getSelected'
);
var
rowIndex = $(
'#set_schedule'
).datagrid(
'getRowIndex'
,row);
//获取行号
var
thisTarget = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'bb3'
}).target;
var
value = thisTarget.combobox(
'getValue'
);
var
target = $(
'#set_schedule'
).datagrid(
'getEditor'
, {
'index'
:rowIndex,
'field'
:
'eveningTeacherId'
}).target;
target.combobox(
'clear'
);
//清除原来的数据
var
url =
'teacherAction_search.action?teacherTypeId2='
+value;
target.combobox(
'reload'
, url);
//联动下拉列表重载
}
}
}
},
{
field:
'eveningTeacherId'
,
title:
'主讲老师'
,
width:100 ,
editor : {
type :
'combobox'
,
options : {
url:
'teacherAction_search.action'
,
valueField:
'id'
,
textField:
'name'
}
}
}
]] ,
pagination:
true
,
pageSize: 10 ,
pageList:[5,10,15,20,50] ,
toolbar:[
{
text:
'新增课程'
,
iconCls:
'icon-add'
,
handler:
function
(){
if
(editing == undefined){
flag =
'add'
;
//1 先取消所有的选中状态
$(
'#set_schedule'
).datagrid(
'unselectAll'
);
//2追加一行
$(
'#set_schedule'
).datagrid(
'appendRow'
,{description:
''
});
//3获取当前页的行号
editing = $(
'#set_schedule'
).datagrid(
'getRows'
).length -1;
//4选中并开启编辑状态
$(
'#set_schedule'
).datagrid(
'selectRow'
,editing);
$(
'#set_schedule'
).datagrid(
'beginEdit'
, editing);
}
}
}
/* ,{
text:'修改课程',
iconCls:'icon-edit' ,
handler:function(){
var arr = $('#set_schedule').datagrid('getSelections');
if(arr.length != 1){
$.messager.show({
title:'提示信息',
msg:'只能选择一条记录进行修改!'
});
} else {
if(editing == undefined){
flag = 'edit';
//根据行记录对象获取该行的索引位置
editing = $('#set_schedule').datagrid('getRowIndex' , arr[0]);
//开启编辑状态
$('#set_schedule').datagrid('beginEdit',editing);
}
}
}
} */
,{
text:
'保存课程'
,
iconCls:
'icon-save'
,
handler:
function
(){
//保存之前进行数据的校验 , 然后结束编辑并师傅编辑状态字段
if
($(
'#set_schedule'
).datagrid(
'validateRow'
,editing)){
$(
'#set_schedule'
).datagrid(
'endEdit'
, editing);
editing = undefined;
}
}
},{
text:
'删除课程'
,
iconCls:
'icon-remove'
,
handler:
function
(){
var
arr = $(
'#set_schedule'
).datagrid(
'getSelections'
);
if
(arr.length <= 0 ){
$.messager.show({
title:
'提示信息'
,
msg:
'请选择进行删除操作!'
});
}
else
{
$.messager.confirm(
'提示信息'
,
'确认删除?'
,
function
(r){
if
(r){
var
ids =
''
;
for
(
var
i = 0 ; i < arr.length ; i++){
ids += arr[i].id +
','
;
}
ids = ids.substring(0,ids.length-1);
$.post(
'scheduleAction_delete.action'
, {ids:ids},
function
(result){
$(
'#set_schedule'
).datagrid(
'reload'
);
$.messager.show({
title:
'提示信息'
,
msg:
'操作成功!'
});
});
}
else
{
return
;
}
});
}
}
},{
text:
'取消操作'
,
iconCls:
'icon-cancel'
,
handler:
function
(){
//回滚数据
$(
'#set_schedule'
).datagrid(
'rejectChanges'
);
editing = undefined;
}
}
] ,
onAfterEdit:
function
(index , record){
var
data = $(
'#moduleform'
).serialize();
$.post(flag==
'add'
?
'scheduleAction_addSchedule.action?'
+data:
'scheduleAction_updateSchedule.action'
, record ,
function
(result){
var
data = $.parseJSON(result);
$(
'#set_schedule'
).datagrid(
'reload'
);
$.messager.show({
title:
'提示信息'
,
msg:data.message
});
},
'text'
);
}
});
});
</script>
<form id=
"moduleform"
method=
"post"
>
<s:hidden name=
"sureDocumentId"
id=
"sureDocumentId"
></s:hidden>
<table cellspacing=
"1"
cellpadding=
"5"
class=
"tb_background2"
width=
"100%"
>
<tr>
<td width=
"20%"
class=
"td_right"
>总学时:</td>
<td width=
"28%"
class=
"td_left"
>
<s:textfield name=
"totalLearnTime"
id=
"totalLearnTime"
size=
"32"
/>学时
</td>
<td width=
"20%"
class=
"td_right"
>是否可见:</td>
<td width=
"28%"
class=
"td_left"
>
<s:select list=
"#{'0':'可见','1':'不可见' }"
cssStyle=
"width:200px;"
name=
"type"
id=
"type"
></s:select>
</td>
</tr>
</table>
</form>
<table id=
"set_schedule"
></table>
</body>
jQuery EasyUI编辑DataGrid用combobox实现多级联动的更多相关文章
- 第二百二十二节,jQuery EasyUI,DataGrid(数据表格)组件
jQuery EasyUI,DataGrid(数据表格)组件 学习要点: 1.加载方式 2.分页功能 本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于 Pa ...
- JQuery EasyUI的datagrid的使用方式总结
JQuery EasyUI的datagrid的使用方式总结第一步:添加样式和js脚本在前台添加展示数据表格的table元素 例如: <div> <table id="tt& ...
- jQuery EasyUI 1.4.4 Combobox无法检索中文输入的问题
在项目里使用了EasyUI的Combobox,当ComboBox的item是英文时,都能正常检索出对应项,但是如果使用中文输入法输入几个字母然后通过按shift键输入时,奇怪的事情发生了,combob ...
- 给Jquery easyui 的datagrid 每行增加操作链接(转)
http://www.thinkphp.cn/code/207.html 通过formatter方法给Jquery easyui 的datagrid 每行增加操作链接我们都知道Jquery的EasyU ...
- JQuery EasyUI中datagrid的使用
在学习过程中,可以参照JQuery EasyUI的官方网站学习.地址:http://www.jeasyui.com/demo/main/index.php 在学习JQuery EasyUI中的Data ...
- jQuery EasyUI之DataGrid使用示例
jQuery EasyUI是一个轻量级的Web前端开发框架,提供了很多的现成组件帮助程序员减轻前端代码开发量,之前有个项目中就用到了其中的DataGrid. jQuery EasyUI框架的官方主页: ...
- JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式(转)
需求如下 现有数据列三列 Name,Age,CreateDate 数据 张三,18,2000-12-09 :12:34:56 李四,28,2000-12-09 :12:34:56 王麻子,38,200 ...
- jquery easyui的datagrid在初始化的时候会请求两次URL?
我们项目前端用的是jquery easyui,刚开始使用datagrid加载列表初始化时总是请求两次URL,这让人非常不解,怎么总是请求两次呢?数据一多,加载速度明显变慢,通过查资料才知道原来是重复声 ...
- 给Jquery easyui 的datagrid 每行添加操作链接
背景 我们都知道Jquery的Easy-UI的datagrid能够加入而且自己定义Toolbar,这样我们选择一行然后选择toolbar的对应button就能够对这行的数据进行操作.但实际项目里我们可 ...
随机推荐
- Office 2007 SP3 正试版补丁包下载
这仅仅是下载补丁包.下载地址也是微软官网的.以下是MD5是我下载后校验的. 2007 Microsoft Office 套件 Service Pack 3 (SP3) 文件名: office2007s ...
- python 列表合并
列表合并主要有以下方法: 1.用list的extend方法,L1.extend(L2),该方法将参数L2的全部元素添加到L1的尾部 结果:[1, 2, 3, 4, 5, 1, 20, 30] 2.用切 ...
- POJ 3020 Antenna Placement 最大匹配
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 3182 ...
- MyEclipse图表工具Birt的使用技巧(三)--连接webservice数据源
Web Services 技术是一套标准.它定义了应用程序怎样在Web上实现互操作. 用户能够使用不论什么语言.在不同的平台下编写Web Services.然后通过Web Services 的标准来对 ...
- 适用于 Charles任 意版 本的 注 册 码
// Charles Proxy License // 适用于Charles任意版本的注册码,谁还会想要使用破解版呢. // Charles 4.2目前是最新版,可用. Registered Name ...
- MonoDevelop 的一些设置
原地址:http://hi.baidu.com/next2_me MonoDevelop保存跳到顶部 Saving in MonoDevelop goes to the top line. MonoD ...
- iOS项目中的网络请求和上下拉刷新封装
代码地址如下:http://www.demodashi.com/demo/11621.html 一.运行效果图 现在的项目中不可避免的要使用到网络请求,而且几乎所有软件都有上下拉刷新功能,所以我在此对 ...
- Android Camera 使用小结。两种方法:一是调用系统camera app,二是自己写camera程序。
源文链接:http://www.cnblogs.com/franksunny/archive/2011/11/17/2252926.html Android Camera 使用小结 Android手机 ...
- 集成ueditor工具
摘要: 摘要: 版权声明:本文为博主原创文章,未经博主允许不得转载. UEditor 是百度的一套开源的在线HTML编辑器. 第一步:去官网看官网文档,了解这个工具如何使用以及下载,本人下载的是1.4 ...
- linux tomacat 之部署 war包
之前一篇写的是tomcat的linux安装,其中主要是jre 的问题,接下来讲讲 tomcat发布war包 这是一个相对简单的过程 打好war包后,将war包上传到/usr/local/tomcat/ ...