1. 程式人生 > >day04-easyUId atagrid使用方法-使用easyUI提供的API建立datagrid

day04-easyUId atagrid使用方法-使用easyUI提供的API建立datagrid

<!-- 方式三:使用easyUI提供的API建立datagrid -->

         <script type="text/javascript">

                   $(function(){

                           

//頁面載入完成後,建立資料表格datagrid

                            $("#mytable").datagrid({

                                    

//定義標題行所有的列

                                     columns:[[

                                    

          {title:'編號',field:'id',checkbox:true},

                                               {title:'姓名',field:'name'},

                                               {title:'年齡',field:'age'},

                                               {title:'地址',field:'address'}

                                               ]],

                                     //指定資料表格傳送ajax請求的地址

                                     url:'${pageContext.request.contextPath}/json/datagrid_data.json',

                                     rownumbers:true,

                                     singleSelect:true,

                                     //定義工具欄

                                     toolbar:[

                                              {text:'新增',iconCls:'icon-add',

                                                 //為按鈕繫結單擊事件

                                                 handler:function(){

                                                        alert('add...');

                                               }

                                              },

                                              {text:'刪除',iconCls:'icon-remove'},

                                              {text:'修改',iconCls:'icon-edit'},

                                              {text:'查詢',iconCls:'icon-search'}

                                              ],

                                     //顯示分頁條

                                     pagination:true

                            });

                   });

         </script>

 

如果資料表格中使用了分頁條,要求服務端響應的json變為: