你的位置:首页 > Java教程

[Java教程]DWZ动态Table


<!-- index.jsp>>>index>>>固定资产管理 --><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@include file="/context/devuxTags.jsp"%><div class="pageContent">  <div class="panelBar">    <ul class="toolBar">      <li><a class="add"><span>添加</span></a></li>      <li><a class="delete"><span>删除</span></a></li>      <li><a class="edit" title="修改"><span>修改</span></a></li>            <li class="line">line</li>          </ul>    <select class="combox" id="fixedAssetsType">      <option value="computer">计算机主机</option>      <option value="50">计算机显示器</option>      <option value="100">办公桌</option>      <option value="200">办公座椅</option>    </select>  </div>    <div id="jTableDynamic99999"></div>

 

<script type="text/javascript">(function($) {  $.fn.jTableDynamic = function(options) {    options = $.extend(true, {      cols: [],      url: "",      pagging: false,      numPerPage: 10    }, options);    var $table = $(this);    loadDynamicTableData = function(numPerPage, pageNum) {      $table.html('<table width="100%"><thead></thead><tbody></tbody></table>');      if (options.pagging) {        var pagination = '<div >' + '<div ><span>每页显示</span>' + '<select name="numPerPage"><option value="10">10</option><option value="20">20</option><option value="50">50</option></select>' + '<span>条,共<label id="totalCount"></label>条</span></div>' + '<div targetType="" totalCount="150" numPerPage="10" pageNumShown="10" currentPage="1"></div></div>';        $table.append(pagination);      }      var cols = options.cols;      var fixedAssetsHead = "<tr>";      for (var idx = 0; idx < cols.length; idx++) {        var col = cols[idx];        fixedAssetsHead += '<th width="' + col.width + 'px">' + '<div title="' + col.name + '" >' + col.name + '</div></th>';      }      fixedAssetsHead += '</tr>';      $table.find('thead').html(fixedAssetsHead);      $.ajax({        type: 'POST',        url: options.url,        data: {          numPerPage: numPerPage,          pageNum: pageNum        },        dataType: 'json',        contentType: "application/x-www-form-urlencoded; charset=utf-8",        async: false, // 处理页面初始化用ajax获取并设置表格内容后,表格没有点击事件、单元格不对齐等。        success: function(respMsg, textStatus, jqXHR) {          if (respMsg.code == 200) {            var data = respMsg.data;            var rows = data.rows;            var total = data.total;            if (rows instanceof Array) {              $table.find('#totalCount').html(total);              var content = "";              try {                for (var idxd = 0; idxd < rows.length; idxd++) {                  content += '<tr target="sid_user" rel="' + idxd + '" >';                  for (var idx = 0; idx < cols.length; idx++) {                    var col = cols[idx];                    content += "<td>" + rows[idxd][col.code] + "</td>";                  }                  content += "</tr>";                }                $table.find("select[name='numPerPage']").val(numPerPage);                $table.find('.pagination').attr("totalCount", total);                $table.find('.pagination').attr("currentPage", pageNum);                $table.find('.pagination').attr("numPerPage", numPerPage);              } catch (exception) {                content = "";                alertMsg.error('表格数据格式不正确!');              }              $table.find('tbody').html(content);            } else {              alertMsg.error('服务器返回的表格数据格式不正确!');            }          } else {            alertMsg.error('查询表格数据时发生错误!\n' + respMsg.msg);          }        },        error: function(