jQuery EasyUI从入门到精通(12)DataGrid(2)

2025-11-16 01:37:07

1、DataGrid Selection(数据表格选择器),Choose a selection mode and select one or more rows.

<!DOCTYPE html>

<html>

<head>

   <meta charset="UTF-8">

   <title>DataGrid Selection - jQuery EasyUI Demo</title>

   <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">

   <link rel="stylesheet" type="text/css" href="../../themes/icon.css">

   <link rel="stylesheet" type="text/css" href="../demo.css">

   <script type="text/javascript" src="../../jquery.min.js"></script>

   <script type="text/javascript" src="../../jquery.easyui.min.js"></script>

</head>

<body>

   <h2>DataGrid Selection</h2>

   Choose a selection mode and select one or more rows.

   <div style="margin:20px 0;">

       <a href="#" class="easyui-linkbutton" onclick="getSelected()">GetSelected</a>

       <a href="#" class="easyui-linkbutton" onclick="getSelections()">GetSelections</a>

   </div>

   <table id="dg" class="easyui-datagrid" title="DataGrid Selection" style="width:700px;height:250px"

           data-options="singleSelect:true,url:'datagrid_data1.json',method:'get'">

       <thead>

           <tr>

               <th data-options="field:'itemid',width:80">Item ID</th>

               <th data-options="field:'productid',width:100">Product</th>

               <th data-options="field:'listprice',width:80,align:'right'">List Price</th>

               <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>

               <th data-options="field:'attr1',width:250">Attribute</th>

               <th data-options="field:'status',width:60,align:'center'">Status</th>

           </tr>

       </thead>

   </table>

   <div style="margin:10px 0;">

       <span>Selection Mode: </span>

       <select onchange="$('#dg').datagrid({singleSelect:(this.value==0)})">

           <option value="0">Single Row</option>

           <option value="1">Multiple Rows</option>

       </select>

   </div>

   <script type="text/javascript">

       function getSelected(){

           var row = $('#dg').datagrid('getSelected');

           if (row){

               $.messager.alert('Info', row.itemid+":"+row.productid+":"+row.attr1);

           }

       }

       function getSelections(){

           var ss = [];

           var rows = $('#dg').datagrid('getSelections');

           for(var i=0; i<rows.length; i++){

               var row = rows[i];

               ss.push('<span>'+row.itemid+":"+row.productid+":"+row.attr1+'</span>');

           }

           $.messager.alert('Info', ss.join('<br/>'));

       }

   </script>

</body>

</html>

jQuery EasyUI从入门到精通(12)DataGrid(2)

2、DataGrid Selection(数据表格选择器),运行效果如下图所示。

jQuery EasyUI从入门到精通(12)DataGrid(2)

3、CheckBox Selection on DataGrid(数据表格DataGrid上的复选框选择),Click the checkbox on header to select or unselect all selections.

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>CheckBox Selection on DataGrid - jQuery EasyUI Demo</title>

    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">

    <link rel="stylesheet" type="text/css" href="../../themes/icon.css">

    <link rel="stylesheet" type="text/css" href="../demo.css">

    <script type="text/javascript" src="../../jquery.min.js"></script>

    <script type="text/javascript" src="../../jquery.easyui.min.js"></script>

</head>

<body>

    <h2>CheckBox Selection on DataGrid</h2>

    Click the checkbox on header to select or unselect all selections.

    <div style="margin:20px 0;"></div>

    

    <table id="dg" class="easyui-datagrid" title="CheckBox Selection on DataGrid" style="width:700px;height:250px"

            data-options="rownumbers:true,singleSelect:true,url:'datagrid_data1.json',method:'get'">

        <thead>

            <tr>

                <th data-options="field:'ck',checkbox:true"></th>

                <th data-options="field:'itemid',width:80">Item ID</th>

                <th data-options="field:'productid',width:100">Product</th>

                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>

                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>

                <th data-options="field:'attr1',width:220">Attribute</th>

                <th data-options="field:'status',width:60,align:'center'">Status</th>

            </tr>

        </thead>

    </table>

    <div style="margin:10px 0;">

        <span>Selection Mode: </span>

        <select onchange="$('#dg').datagrid({singleSelect:(this.value==0)})">

            <option value="0">Single Row</option>

            <option value="1">Multiple Rows</option>

        </select><br/>

        SelectOnCheck: <input type="checkbox" checked onchange="$('#dg').datagrid({selectOnCheck:$(this).is(':checked')})"><br/>

        CheckOnSelect: <input type="checkbox" checked onchange="$('#dg').datagrid({checkOnSelect:$(this).is(':checked')})">

    </div>

</body>

</html>

jQuery EasyUI从入门到精通(12)DataGrid(2)

4、CheckBox Selection on DataGrid(数据表格DataGrid上的复选框选择),运行效果如下图所示。

jQuery EasyUI从入门到精通(12)DataGrid(2)

5、DataGrid with Toolbar(带工具栏的数据表格),Put buttons on top toolbar of DataGrid.

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>DataGrid with Toolbar - jQuery EasyUI Demo</title>

    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">

    <link rel="stylesheet" type="text/css" href="../../themes/icon.css">

    <link rel="stylesheet" type="text/css" href="../demo.css">

    <script type="text/javascript" src="../../jquery.min.js"></script>

    <script type="text/javascript" src="../../jquery.easyui.min.js"></script>

</head>

<body>

    <h2>DataGrid with Toolbar</h2>

    Put buttons on top toolbar of DataGrid.

    <div style="margin:20px 0;"></div>

    <table class="easyui-datagrid" title="DataGrid with Toolbar" style="width:700px;height:250px"

            data-options="rownumbers:true,singleSelect:true,url:'datagrid_data1.json',method:'get',toolbar:toolbar">

        <thead>

            <tr>

                <th data-options="field:'itemid',width:80">Item ID</th>

                <th data-options="field:'productid',width:100">Product</th>

                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>

                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>

                <th data-options="field:'attr1',width:240">Attribute</th>

                <th data-options="field:'status',width:60,align:'center'">Status</th>

            </tr>

        </thead>

    </table>

    <script type="text/javascript">

        var toolbar = [{

            text:'Add',

            iconCls:'icon-add',

            handler:function(){alert('add')}

        },{

            text:'Cut',

            iconCls:'icon-cut',

            handler:function(){alert('cut')}

        },'-',{

            text:'Save',

            iconCls:'icon-save',

            handler:function(){alert('save')}

        }];

    </script>

</body>

</html>

jQuery EasyUI从入门到精通(12)DataGrid(2)

6、DataGrid with Toolbar(带工具栏的数据表格),运行效果如下图所示。

jQuery EasyUI从入门到精通(12)DataGrid(2)

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢