1. 程式人生 > >EasyUI建立DataGrid及凍結列的兩種方式

EasyUI建立DataGrid及凍結列的兩種方式

   第一種方式:通過HTML標籤建立資料表格控制元件

<table class="easyui-datagrid" title="基本資料表格"
        style="width: 700px; height: 250px"
        data-options="singleSelect:true,collapsible:true,url:'${pageContext.request.contextPath}/datagridData.do'">
        <thead data-options="frozen:true">
<tr> <th data-options="field:'stuId',width:100">學生ID</th> <th data-options="field:'stuName',width:100">學生姓名</th> </tr> </thead> <thead> <tr> <
th data-options="field:'stuSex',width:100">學生性別</th> <th data-options="field:'stuAge',width:100">學生年齡</th> <th data-options="field:'stuEmail',width:100,align:'center'">學生郵箱</th> <th data-options="field:'stuQQ',width:100,align:'right'"
>學生QQ</th> <th data-options="field:'stuAddress',width:200,align:'center'">學生地址</th> </tr> </thead> <tbody> <c:forEach var="student" items="${studentList}"> <tr> <td>${student.stuId}</td> <td>${student.stuName}</td> <td>${student.stuSex}</td> <td>${student.stuAge}</td> <td>${student.stuEmail}</td> <td>${student.stuQQ}</td> <td>${student.stuAddress}</td> </tr> </c:forEach> </tbody> </table>

    data-options="frozen:true"凍結列

   第二種方式:使用Javascript去建立資料表格控制元件

<body>
    <table id="studentList">
        <tbody>
            <c:forEach var="student" items="${studentList}">
                <tr>
                    <td>${student.stuId}</td>
                    <td>${student.stuName}</td>
                    <td>${student.stuSex}</td>
                    <td>${student.stuAge}</td>
                    <td>${student.stuEmail}</td>
                    <td>${student.stuQQ}</td>
                    <td>${student.stuAddress}</td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
</body>
<script type="text/javascript">
    $('#studentList').datagrid({
        title : '基本資料表格',
        width : 700,
        height : 250,
        url : '${pageContext.request.contextPath}/datagridData.do',
        frozenColumns : [ [ {
            field : 'stuId',
            title : '學生ID',
            width : 100
        }, {
            field : 'stuName',
            title : '學生姓名',
            width : 100
        } ] ],
        columns : [ [ {
            field : 'stuSex',
            title : '學生性別',
            width : 100
        }, {
            field : 'stuAge',
            title : '學生年齡',
            width : 100
        }, {
            field : 'stuEmail',
            title : '學生郵箱',
            width : 100
        }, {
            field : 'stuQQ',
            title : '學生QQ',
            width : 100
        }, {
            field : 'stuAddress',
            title : '學生地址',
            width : 200,
            align : 'center'
        } ] ]

    });
</script>

   frozenColumns屬性凍結列