前一篇博客写到项目中的广告位管理,当时没有写到今天的问题,这个问题当时也是困扰我好久。

经过自己的努力和同志们的帮助,最后最终解决。

实现要求把全部的广告位后面的单选button设成一组,目的是一个广告位仅仅能显示一张图片。仅仅是简单的在特定列加入单选button事实上并没有太大的难度,后期还要通过选中单选button把选中内容传回到Controller(这里用的是MVC),从网上找了不少资料而且通过Leader
Wang的帮助,能够说实现方式有些曲折,但终于效果还是令人惬意。

核心代码例如以下:

  1. <table id="tt"></table>

  1. $(function () {
  2. $('#tt').datagrid({
  3. url: '/AdvertisementManage/QueryAdvertisement',
  4. title: '广告位管理(类型一)',
  5. width: 700,
  6. height: 'auto',
  7. fitColumns: true,
  8. pagination: true,//分页显示
  9. rownumbers: true,
  10. onClickCell: onClickCell,//点击单元格触发事件
  11. columns: [[
  12. { field: 'AdvertisementID', title: '序号', width: 90, align: 'center' },
  13. { field: 'AdvertisementName', title: '赞助商', width: 111, align: 'center' },
  14. { field: 'AdvertisementUrl', title: '广告位链接', width: 160, align: 'center' },
  15. { field: 'TimeStamp', title: '加入时间', width: 80, align: 'center' },
  16. { field: 'UserID', title: '操作员', width: 80, align: 'center' },
  17. { field: 'AdvertisementLocation', title: '广告位置', width: 80, align: 'center' },
  18. {
  19. field: 'IsEnable', title: '是否显示', width: 60, align: 'center',
  20.  
  21. //调用formater函数对列进行格式化。使其显示单选button(全部单选buttonname属性设为统一。这样就仅仅能有一个处于选中状态)
  22. formatter: function (value, row, index) {
  23.  
  24. if (row.IsEnable == 1) {
  25. //假设属性值等于1,则处于选中状态(默认表格中全部单选button最多仅仅能有一个值等于1)
  26. var s = '<input name="isShow" type="radio" checked="checked" onclick="clk()"/> ';
  27.  
  28. }
  29. else {
  30. var s = '<input name="isShow" type="radio" onclick="clk()"/> ';
  31. }
  32. return s;
  33. }
  34.  
  35. }
  36. ]],
  37. onHeaderContextMenu: function (e, field) {
  38. e.preventDefault();
  39. if (!$('#tmenu').length) {
  40. createColumnMenu();
  41. }
  42. $('#tmenu').menu('show', {
  43. left: e.pageX,
  44. top: e.pageY
  45. });
  46. }
  47. });
  48. });
  49.  
  50. var id = undefined;//公共变量
  51.  
  52. //触发单元格事件
  53. function onClickCell(rowIndex, field, value) {
  54. var row = $("#tt").datagrid('selectRow', rowIndex);//返回触发单元格的行标
  55. var r1 = $("#tt").datagrid('getSelected');//返回被选中的行
  56. id = r1.AdvertisementID;//返回该行的id
  57.  
  58. }

当选中了单选button。触发单元格事件就被运行,获得该单元格的所在的行对象,然后就能够得到该行随意属性了。

EasyUI——DataGrid中嵌入Radio的更多相关文章

  1. 在EasyUI的DataGrid中嵌入Combobox

    在做项目时,须要在EasyUI的DataGrid中嵌入Combobox,花了好几天功夫,在大家的帮助下,最终看到了它的庐山真面: 核心代码例如以下: <html> <head> ...

  2. easyui datagrid中 多表头方法总结

    easyui datagrid中怎么设置表头成多行显示呢?其实很简单,就是给datagrid的columns属性设置成多个数组就行了.下面直接看例子吧,这是一个两行表头的,按照此方法,还可以设置三行表 ...

  3. JQuery easyUi datagrid 中 自定义editor作为列表操作按钮列

    转自   http://blog.csdn.net/tianlincao/article/details/7494467 前言 JQuery easyUi datagrid 中 使用datagrid生 ...

  4. easyui datagrid 中序列化后的日期格式化

    1.在easyui datagrid 中序列化后的日期显示为:/Date(1433377800000)/ 2.格式化后的显示为: 2015-06-04 08:30:00 3.使用代码如下: 3.1. ...

  5. easyui datagrid中datetime字段的显示和增删改查问题

    datagrid中datetime字段的异常显示: 使用过easyui datagrid的应该都知道,如果数据库中的字段是datetime类型,绑定在datagrid显式的时候会不正常显示,一般需要借 ...

  6. EasyUi DataGrid中数据编辑方式及编辑后数据获取,校验处理

    EasyUi中的DataGrid提供前台编辑的相关函数. 实现客户选中DataGrid中一列后,对选中列中的一个字段进行编辑,并对数据进行实时校验后,传递至后台保存的需求, 主要涉及到DataGrid ...

  7. easyui dialog 中嵌入html页面

    最近使用easyui比较多,这个插件确实很好用.在使用时也遇到了大大小小的问题,好在都一一解决了. 记录一下今天遇到的问题. 目的:用easyui的dialog嵌入一个html页面(html中仍有要执 ...

  8. JQuery easyUi datagrid 中 editor 动态设置最大值最小值

    前言 近来项目中使用到 easyui 来进行页面设计,感觉挺方便的,但是网上除了api外,其他有价值的资料比较少,故在此分享一点经验,供大家参考.   问题 JQuery easyUi datagri ...

  9. easyui datagrid中关联combox

    datagrid中列上关联combobox{ field: 'SysCode', title: '系统代码', width: 150, align: 'left', editor: { type: ' ...

随机推荐

  1. POJ 1723 SOLDIERS

    SOLDIERS Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: 1 ...

  2. 修改cloudera manager的端口号

    最近想在测试机装一个hadoop测试集群debug玩玩,然后就用cloudera manager装吧 这回使用rpm安装失败了,在网上搜到Cloudera Manager 5和CDH5离线安装说需要用 ...

  3. hdu 1005 Number Sequence(矩阵连乘+二分快速求幂)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1005 代码: #include<iostream> #include<stdio.h&g ...

  4. [Poi] Build and Analyze Your JavaScript Bundles with Poi

    Ever wonder where those extra KB in your bundle are coming from? This lesson walks you through runni ...

  5. setTimeOut函数传参数

    这样使用,后面的4000无效 setTimeout(removeGift(customer_id,gift_id),4000); function removeGift(customer_id,gif ...

  6. while my time-- , will the meaning++?

    // while my time--,will the meaning++? // However,what's the meaning of life ? while(tomorrow>0){ ...

  7. JS中部分 Array 对象方法介绍

    1.concat() concat() 方法用于连接两个或多个数组.该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本 <script type="text/javascrip ...

  8. 10G安装DataGuard

    最后更新时间:2013年8月4日,星期日 ★ oracle 10G安装环境 数据库软件安装环境不详细描述,网上到处有这方面资料,下面只简单描述下. 也可参考官方文档: http://docs.orac ...

  9. 《TensorFlow学习指南深度学习系统构建详解》英文PDF+源代码+部分中文PDF

    主要介绍如何使用 TensorFlow 框架进行深度学习系统的构建.涉及卷积神经网络.循环神经网络等核心的技术,并介绍了用于图像数据和文本序列数据的模型.给出了分布式深度学习系统在TensorFlow ...

  10. oracle查询字段大于指定长度的数据

    select * from MES_MACHINE_RECORD t where length(t.bar_code2)<10 ;