在 jQuery EasyUI 的 DataGrid 中,你可以通过使用 sortable 属性来启用或禁用列的排序功能。默认情况下,DataGrid 中的列都是可以排序的。以下是一个简单的例子,演示了如何使用 sortable 属性来设置列的排序:
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>jQuery EasyUI 设置排序示例</title>
    <!-- 引入 jQuery 库 -->
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
    <!-- 引入 EasyUI 样式和脚本文件 -->
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
    <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>

    <!-- 创建 EasyUI Datagrid -->
    <table id="datagrid" class="easyui-datagrid" style="width:100%;height:300px"
           url="your_data_url"
           pagination="true"
           rownumbers="true"
           fitColumns="true">
        <thead>
            <tr>
                <!-- 列定义,其中 'sortable' 属性用于设置排序 -->
                <th field="column1" width="100" sortable="true">列1</th>
                <th field="column2" width="100" sortable="false">列2</th>
                <!-- 添加更多列... -->
            </tr>
        </thead>
    </table>

</body>
</html>

在上述代码中,每个列的定义中都包含了一个 sortable 属性,该属性用于启用或禁用列的排序。在示例中,列1是可以排序的(sortable="true"),而列2是禁用排序的(sortable="false")。

你可以根据需要设置列的排序属性,以满足你的实际需求。确保替换 "your_data_url" 为实际数据源的 URL,并根据你的需求修改列的名称和数量。


转载请注明出处:http://www.pingtaimeng.com/article/detail/13111/jQuery EasyUI