用JQuery让GT-Grid的下拉列表实现二级联动
来源:互联网 发布:心蓝数据官网 编辑:程序博客网 时间:2024/06/18 12:16
原链接:http://www.iteye.com/topic/603857
主题:用JQuery让GT-Grid的下拉列表实现二级联动
最近项目里面非要实现下列列表的二级联动,由于GT-Grid的下拉列表不支持二级联动,只有自己慢慢摸索了。
注意:1.如果用jQuery1.3.2在ie下面有问题(不能联动),所以建议使用jQuery1.4.2;
更新:由于上传的附件是tomcat下的工程文件,现在修改为myeclipse工程目录。
更新2:增加了一种方法,比方法一更精确。附件并未更新,请自行更新代码。
相关代码如下:
- $(document).ready(function() {
- var dsConfig = {
- fields : [{
- name : 'id',
- type : 'int'
- }, {
- name : 'province',
- type : 'int'
- }, {
- name : 'city',
- type : 'int'
- }, {
- name : 'total',
- type : 'float'
- }],
- uniqueField : 'id'
- };
- var colsConfig = [{
- id : 'id',
- header : "ID",
- headAlign : 'center',
- width : 80,
- align : 'center'
- }, {
- id : 'province',
- header : "省份",
- headAlign : 'center',
- width : 80,
- align : 'center',
- renderer : GT.Grid.mappingRenderer(province, '未知省份'),// 可以动态取得数据库里面的值
- editor : {
- type : 'select',
- options : province
- }
- }, {
- id : 'city',
- header : "城市",
- headAlign : 'center',
- width : 80,
- align : 'center',
- renderer : GT.Grid.mappingRenderer(city, '未知城市'),// 动态取得数据库里面的值
- editor : {
- type : 'select',
- // options : city //这里可以只为省份为1的城市列表。
- options : {
- 1 : '武汉',
- 2 : '鄂州',
- 3 : '恩施',
- 4 : '黄冈',
- 5 : '黄石',
- 6 : '荆门',
- 7 : '荆州',
- 8 : '潜江'
- }
- }
- }, {
- id : 'total',
- header : "总计",
- headAlign : 'center',
- width : 130,
- align : 'center'
- }];
- var province_value = "";// 用于存放省份下拉框值
- var gridConfig = {
- id : "grid",
- dataset : dsConfig,
- columns : colsConfig,
- container : 'grid_container',
- toolbarPosition : 'bottom',
- toolbarContent : toolbar,// 定义为一个变量,可以让不同的角色能看到不同的toolbar,达到控制角色目的
- pageSize : 10,
- pageSizeList : [5, 10, 15],
- loadURL : 'all.action',
- resizable : true,
- autoLoad : true,
- selectRowByCheck : true,
- remotePaging : false,
- onComplete : function(grid) {
- $(".gt-menuitem:last-child").hide();
- // 二级联动
- if ($("#company_id").length == 0) {
- $($(".gt-editor-text")[0]).attr("id","company_select");
- $($(".gt-editor-text")[1]).attr("id","department_select");
- }
- $("#company_select").bind("change",function() {
- var url = "companyLink";
- var params = {
- company : $('#company_select').val()
- };
- $.post(url, params, callBack, 'json');
- function callBack(date) {
- var select_value = "";
- $.each(date.info, function(i, item) {
- select_value = select_value + "<option value='" + item.id +"'>" + item.va + "</option>";
- });
- $("#department_select").html(select_value);
- }
- });
- }
- clickStartEdit : false,
- reloadAfterSave : true,
- recountAfterSave : true,
- defaultRecord : {
- id : 1,
- province : 1,
- city : 1,
- total : 111.01
- }
- };
- var mygrid = new GT.Grid(gridConfig);
- GT.Utils.onLoad(GT.Grid.render(mygrid));
$(document).ready(function() {var dsConfig = {fields : [{ name : 'id', type : 'int' }, { name : 'province', type : 'int' }, { name : 'city', type : 'int' }, { name : 'total', type : 'float' }],uniqueField : 'id'};var colsConfig = [{ id : 'id', header : "ID", headAlign : 'center', width : 80, align : 'center' }, { id : 'province', header : "省份", headAlign : 'center', width : 80, align : 'center', renderer : GT.Grid.mappingRenderer(province, '未知省份'),// 可以动态取得数据库里面的值 editor : { type : 'select', options : province } }, { id : 'city', header : "城市", headAlign : 'center', width : 80, align : 'center', renderer : GT.Grid.mappingRenderer(city, '未知城市'),// 动态取得数据库里面的值 editor : { type : 'select', // options : city //这里可以只为省份为1的城市列表。 options : { 1 : '武汉', 2 : '鄂州', 3 : '恩施', 4 : '黄冈', 5 : '黄石', 6 : '荆门', 7 : '荆州', 8 : '潜江' } } }, { id : 'total', header : "总计", headAlign : 'center', width : 130, align : 'center' }];var province_value = "";// 用于存放省份下拉框值var gridConfig = {id : "grid",dataset : dsConfig,columns : colsConfig,container : 'grid_container',toolbarPosition : 'bottom',toolbarContent : toolbar,// 定义为一个变量,可以让不同的角色能看到不同的toolbar,达到控制角色目的pageSize : 10,pageSizeList : [5, 10, 15],loadURL : 'all.action',resizable : true,autoLoad : true,selectRowByCheck : true,remotePaging : false,onComplete : function(grid) { $(".gt-menuitem:last-child").hide(); // 二级联动 if ($("#company_id").length == 0) { $($(".gt-editor-text")[0]).attr("id", "company_select"); $($(".gt-editor-text")[1]).attr("id", "department_select"); } $("#company_select").bind("change", function() { var url = "companyLink"; var params = { company : $('#company_select').val() }; $.post(url, params, callBack, 'json'); function callBack(date) { var select_value = ""; $.each(date.info, function(i, item) { select_value = select_value + "<option value='" + item.id + "'>" + item.va + "</option>"; }); $("#department_select").html(select_value); } }); }clickStartEdit : false,reloadAfterSave : true,recountAfterSave : true,defaultRecord : {id : 1,province : 1,city : 1,total : 111.01}};var mygrid = new GT.Grid(gridConfig);GT.Utils.onLoad(GT.Grid.render(mygrid));
关于如何取class,如:$(".gt-col-grid-province div")
.gt-col-grid-province为td的class,如何定义的呢?gt-col-加上这个grid的id,我的grid的id是“grid",再加上这列的ID,就是:gt-col-grid-province.
赋值给id后两个下拉列表:
- <div class="gt-editor-container">
- <select id="province_select"class="gt-editor-text">
- <option value="1">湖北
- </option>
- <option value="2">福建
- </option>
- <option value="3">宁夏
- </option>
- </select>
- </div>
- <div class="gt-editor-container">
- <select id="city_select"class="gt-editor-text">
- <option value="1">武汉
- </option>
- <option value="2">鄂州
- </option>
- <option value="3">恩施
- </option>
- <option value="4">黄冈
- </option>
- <option value="5">黄石
- </option>
- <option value="6">荆门
- </option>
- <option value="7">荆州
- </option>
- <option value="8">潜江
- </option>
- </select>
- </div>
<div class="gt-editor-container"><select id="province_select" class="gt-editor-text"><option value="1">湖北</option><option value="2">福建</option><option value="3">宁夏</option></select></div><div class="gt-editor-container"><select id="city_select" class="gt-editor-text"><option value="1">武汉</option><option value="2">鄂州</option><option value="3">恩施</option><option value="4">黄冈</option><option value="5">黄石</option><option value="6">荆门</option><option value="7">荆州</option><option value="8">潜江</option></select></div>
主要是用jQuery改变#city_select下拉列表的值。
部分效果图如下:
IE6,Firefox3.6,chrome5下测试通过,欢迎拍砖。
jQuery插件flexigrid使用总结
- 用JQuery让GT-Grid的下拉列表实现二级联动
- jquery实现下拉列表二级联动
- 如何用ci框架+jquery实现下拉列表二级联动
- jQuery结合PHP+MySQL实现二级联动下拉列表[实例]
- 下拉列表的二级联动
- 用Jquery做省市二级联动下拉列表
- JQuery实现下拉列表的联动
- struts+dwr实现下拉列表的二级联动
- Android开发实现二级联动下拉列表
- 二级联动下拉列表JS+html实现
- 二级联动下拉列表JS+html实现
- Android开发实现二级联动下拉列表
- jQuery实现二级联动下拉框
- jQuery ajax 实现下拉框 二级联动
- jQuery实现二级联动下拉框
- JavaScript下拉列表的二级联动
- jQuery实现下拉框省市联动,二级联动
- jquery实现下拉菜单的二级联动,利用json对象从DB取值显示联动
- JS 获取span标签中的值的代码 支持ie与firefox
- Archlinux从3.6.9-1-ARCH升级到3.6.11-1-ARCH后vmware 9不能启动的解决办法
- python学习1
- SZNOI d017题解
- TINYC写个8052虚拟机(3) Intel MCS-805x寄存器定义
- 用JQuery让GT-Grid的下拉列表实现二级联动
- 构建高可扩Web架构和分布式系统实战
- SZNOI d018题解
- java 页面获取session值
- jquery仿QQ消息框
- Factstone Benchmark
- JavaScript开发单片机:I/O篇 -- 驱动LED键盘控制IC-FD620K1.
- 编写Linux下Input设备的检测程序
- POJ 2513 Colored Sticks