zoukankan      html  css  js  c++  java
  • Easyui datagrid内容自动撑开页面

    在做项目时会用到Easyui datagrid插件,因为里面的数据各不相一,可能会存在内容无法撑开页面的效果,以下分享一下做得成功的一个案例,如图:

     1 <div id="toolbar" style="padding: 5px;">
     2     <div>
     3         <a href="#" class="easyui-linkbutton" onclick="OpenDiag();" iconcls="icon-add">新增</a>
     4     </div>
     5 </div>
     6 <table class="easyui-datagrid" id="table1" toolbar="#toolbar" style="height: 700px">
     7 </table>
     8 <div id="divAddDiag">
     9     <table class="gentable_con" cellpadding="5">
    10         <tr>
    11             <td class="alignright" style=" 35%">
    12                 关键词标识:
    13             </td>
    14             <td>
    15                 <input id="hdKeyCode" type="hidden" />
    16                 <input id="txtKeyCode" class="easyui-validatebox" data-options="required:true,validType:'length[1,10]',invalidMessage:'最多可输入10个汉字'" />
    17             </td>            
    18         </tr>   
    19         <tr>
    20             <td class="alignright" style=" 35%">
    21                 关键词:
    22             </td>
    23             <td>
    24                 <input id="hdKeys" type="hidden" />
    25                 <input id="txtKeys" class="easyui-validatebox" data-options="required:true,validType:'length[1,10]',invalidMessage:'最多可输入10个汉字'" />
    26             </td>            
    27         </tr>        
    28         <tr>
    29             <td class="alignright" >
    30                 缓存时间:
    31             </td>
    32             <td>
    33                 <input id="txtCacheTime" type="text" />
    34             </td>
    35         </tr>
    36         <tr>
    37             <td class="alignright" >
    38                 频道ID:
    39             </td>
    40             <td>
    41                 <input id="txtChannelID" type="text" />
    42             </td>
    43         </tr>
    44     </table>
    45 </div>
    Web页面代码,MVC3
     1 $(function () {
     2     $("#table1").datagrid({
     3         url: 'GetKeysList',
     4         fit: true,
     5         rownumbers: true,
     6         fitColumns: true,
     7         singleSelect: true,
     8         pagination: true,
     9         pageSize: 30,
    10         pageList: [30, 50, 100],
    11         columns: [[
    12             { field: 'KeyCode', title: '关键词标识',  50 },
    13             { field: 'Keys', title: '关键词',  50 },
    14             { field: 'CacheTime', title: '缓存时间(秒)',  30 },
    15             { field: 'TotalCount', title: '频道ID',  30 },
    16             { field: 'LastCacheDate', title: '最后缓存时间',  50, formatter: dateFormatter },
    17             { field: 'CreateTime', title: '创建时间',  50, formatter: dateFormatter },
    18             { field: 'Oper', title: '操作',  200, formatter: formatterOper }
    19         ]]
    20     });
    21     $("body").css({ visibility: "visible" });
    22 
    23     $(".btn-add").click(function () {
    24         OpenDiag();
    25     });
    26 
    27     Date.prototype.format = function (format) {
    28         var o = {
    29             "M+": this.getMonth() + 1, //
    30             "d+": this.getDate(), //
    31             "h+": this.getHours(), //
    32             "m+": this.getMinutes(), //
    33             "s+": this.getSeconds(), //
    34             "q+": Math.floor((this.getMonth() + 3) / 3), //
    35             "S": this.getMilliseconds() //毫秒
    36             // millisecond
    37         };
    38         if (/(y+)/.test(format))
    39             format = format.replace(RegExp.$1, (this.getFullYear() + "")
    40                 .substr(4 - RegExp.$1.length));
    41         for (var k in o)
    42             if (new RegExp("(" + k + ")").test(format))
    43                 format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
    44                     : ("00" + o[k]).substr(("" + o[k]).length));
    45         return format;
    46     };
    47 });
    48 
    49 function formatterOper(value, rowData, rowIndex) {
    50     return "<a href='#' onclick='EditKey(" + JSON.stringify(rowData) + ")'  data-value=" + JSON.stringify(rowData) + ">编辑</a>" +
    51            "<a href='#' onclick='DeleteKey(this)'  style='margin-left:15px;' data-value='" + rowData.KeyCode + "'>删除</a>";
    52 }
    53 
    54 function dateFormatter(value, rec, index) {
    55     if (value == null || value == '') {
    56         return '';
    57     }
    58     var dt;
    59     if (value instanceof Date) {
    60         dt = value; ;
    61     } else {
    62         dt = new Date(value);
    63         if (isNaN(dt)) {
    64             value = value.replace(//Date((-?d+))//, '$1');
    65             dt = new Date();
    66             dt.setTime(value);
    67         }
    68     }
    69     return dt.format("yyyy-MM-dd hh:mm:ss");
    70 }
    JS代码
  • 相关阅读:
    C#快速随机按行读取大型文本文件
    OpenReadWithHttps
    fiddler不能监听 localhost和 127.0.0.1的问题 .
    C#放缩、截取、合并图片并生成高质量新图的类
    JS判断只能是数字和小数点
    HTML5 Support In Visual Studio 2010
    GridView 获取列字段的几种途径
    微信朋友圈如何同时分享(图片+文字) Android版
    【Android】 PopupWindow使用小结
    Android 第三方应用接入微信平台(2)
  • 原文地址:https://www.cnblogs.com/JackQ/p/4256311.html
Copyright © 2011-2022 走看看