DataTables 的 实例 《一》


1.加载需要的js/css文件





2.
<%@ taglib prefix="s" uri="/struts-tags"%>



ajax:从后台返回的数据格式:

{"aaData":[{"col1":"\t1\t","col2":"\t1\t","col3":"\tasddd1\t","col4":2,"col5":"\tLLO1\t","col6":"\tTom1\t","col7":"\tTommonsd1\t","col8":"\tew\t","col9":"


这个是后台的action

 @Inject
    TCService tcService;

    /**
     * {@inheritDoc}
     * 
     * @see com.opensymphony.xwork2.ActionSupport#input()
     */
    @Override
    public String input() {
        System.out.println("---join in suncess -for test case");
        return INPUT;
    }

    public void findNav() throws IOException {
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("text/html;charset=utf-8");
        List listDato = tcService.findAll();
        String jsonResults = loadTableDataJSON(listDato);
        System.out.println(jsonResults);
        PrintWriter out = response.getWriter();
        out.println(jsonResults);

    }

    private String loadTableDataJSON(List listDto) {
        JSONObject obj = new JSONObject();
        JSONArray lineItemArray = new JSONArray();
        JSONObject jsonObj = null;
        for (Dto dto : listDto) {
            jsonObj = new JSONObject();
            jsonObj.put("col1", dto.getId());
            jsonObj.put("col2", dto.getFlash());
            jsonObj.put("col3", dto.getInformation());
            jsonObj.put("col4", 2);
            jsonObj.put("col5", dto.getIntool());
            jsonObj.put("col6", dto.getName());
            jsonObj.put("col7", dto.getUsername());
            jsonObj.put("col8", dto.getValue());
            String actionStr = "    ";
            jsonObj.put("col9", actionStr);
            lineItemArray.add(jsonObj);
        }
        obj.put("aaData", lineItemArray);
        return obj.toString();
    }

----------------------------------

dataTables
1.DOM 操作 页面table中位置排放:
l - Length changing 每页显示多少条数据选项
f - Filtering input 搜索框
t - The Table 表格
i - Information 表格信息
p - Pagination 分页按钮
r - pRocessing 加载等待显示信息
< and > - div elements 一个div元素
<"#id" and > - div with an id 指定id的div元素
<"class" and > - div with a class 指定样式名的div元素
<"#id.class" and > - div with an id and class 指定id和样式的div元素
"dom": "<'row'<'#mytool.col-xs-5'><'col-xs-7'f>r>" +"t" +"<'row'<'col-xs-5'i><'col-xs-2'l><'col-xs-6'p>>",
2.禁止某一列排序orderable
orderable: false
 {"mData" : 'col4', "sTitle" : 'ck', orderable : false},
 或
 columnDefs:[{
            orderable:false,
            targets:[0,2] //指定的某一列
        }],
3.隐藏列visible
 {"mData" : 'col8', "sTitle" : 'statue',"visible": false},或
  columnDefs:[
{ "targets": [ 2 ],
    "visible": false,
    "searchable": false
},
{
    "targets": [ 3 ],
    "visible": false
}],
4.判断列是否参与搜索用bSearchable
{"mData" : 'col7', "sTitle" : 'tav', "bSearchable": false },
5.设置table的宽度
{"mData" : 'col1', "sTitle" : 'ID',"sWidth": "50%"},
{"mData" : 'col2', "sTitle" : 'label' ,"sWidth": "100px" },
6.分页
bPaginite:true;是否启用分页功能
sPaginationType:two_button  或者full_numbers 分页风格
sFirst:告诉他第一页怎么写
sLast:告诉他最后一页怎么写
sNext:告诉他下一页怎么写
sPrevious:告诉他上一页怎么写
7.语言
"oLanguage":
{
   "sProcessing": "正在加载中......",
     "sLengthMenu": "每页显示 _MENU_ 条记录",
     "sZeroRecords": "对不起,查询不到相关数据!",
      "sEmptyTable": "表中无数据存在!",
    "sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
    "sInfoFiltered": "数据表中共为 _MAX_ 条记录",
    "sSearch": "搜索",
     "oPaginate": {
        "sFirst": "首页",
         "sPrevious": "上一页",
         "sNext": "下一页",
        "sLast": "末页"
}
8.使用JQueryUI
"bJQueryUI": true
9.获取选中一行的信息
$('#aaa').click( function () {
        table.$('tr.selected').eq(0).text();
    } );

DataTables 的 实例 《一》_第1张图片

你可能感兴趣的:(dataTables,java)