EasyUI 동적 생성 열

3824 단어 easyui

        // 
        function query_() {
            var params=xxx;
            var url = "xxxajaxList.do";
            $.post(url,params,showGrid, "json");
        }
        // , 
        function showGrid(data) {
            if (data.data[0].rows.length == 0) {
                $.messager.show({
                    title:' ',
                    msg:' !',
                    showType:'slide'
                });
            }
            var options = {
                rownumbers: true,
                fit:true
            };
            options.columns = eval(data.columns);// , datagrid column 
            dataGrid.datagrid(options);// , datagrid
            var p = $('#datagrid').datagrid('getPager');
            $(p).pagination({
                pageNumber:data.data[0].pageNumber,
                pageSize:data.data[0].pageSize,
                onSelectPage:function(pageNumber, pageSize){
                    $(this).pagination('loading');
                    pagerChange(pageNumber,pageSize);
                    $(this).pagination('loaded');
                },
                onChangePageSize:function(pageNumber,pageSize){
                    $(this).pagination('loading');
                    pagerChange(pageNumber,pageSize);
                    $(this).pagination('loaded');
                }
            });
            dataGrid.datagrid("loadData", eval(data.data[0])); // json 
        }
        function pagerChange(pageNumber,pageSize){
            imonKCI.showZone();
            $("#datagrid_page").val(pageNumber);
            $("#datagrid_rows").val(pageSize);
            query_();
            imonKCI.hideZone();
        }

<input type="hidden" name="page" id="datagrid_page" value="1">
<input type="hidden" name="rows" id="datagrid_rows" value="10">
...
<table id="datagrid" width="100%"></table>


변환된 JSON:
{"columns":[[
{"field": "taskName", "title": "이름", "align": "center", "width": "100"}, {"field": "kpScope", "title": "범위", "align": "center", "width": "100"},
{"field": "중국어", "title": "중국어", "align": "center", "width": "100"}],
"data": [{"pageSize": 10, "pageNumber": 1, "rows": [{"id": "661", "taskName": "xx", "kpScope": "xx", "중국어": "xx"}]}}}}}

public class DataGridColumn {
    private String field;
    private String title;
    private String align="center";
    private String width="100";
...
}


List<DataGridColumn> columns=new ArrayList<DataGridColumn>();
columns.add(new DataGridColumn("taskName"," "));
columns.add(new DataGridColumn("kpScope"," "));

String result="{\"columns\":["+JsonUtil.bean2json(columns)+"],\"data\":[{\"pageSize\":"+rows+",\"pageNumber\":"+page+",\"total\":"+list.size()+",\"rows\":["+rowStr+"]}]}";


좋은 웹페이지 즐겨찾기