当前位置:Gxlcms > JavaScript > 详解EasyUI的DataGrid绑定Json数据源方法

详解EasyUI的DataGrid绑定Json数据源方法

时间:2021-07-01 10:21:17 帮助过:11人阅读

EasyUI给表格绑定数据是最常用的方法,本篇文章主要介绍了EasyUI的DataGrid绑定Json数据源的示例代码,小编分享一下总结出来的两种绑定表格方法,希望能帮助到大家。

第一种:数据存放在数据集中,每一行对应多个值,利用循环把数据绑定到表格

前台代码:


<table id="dg" class="easyui-datagrid" style="width:100%;height:100%;" title="需要设置表格标题" data-options=" 
        rownumbers:true, 
        singleSelect:true, 
        @*autoRowHeight:false,*@ 
        pagination:true 
        @*pageSize:10*@"> 
      <thead> 
        <tr> 
          <th field="colum1">列1</th> 
          <th field="colum2">列2</th> 
          <th field="colum3">列3</th> 
          <th field="colum4">列4</th> 
          <th field="colum5">列5</th> 
          <th field="colum6">列6</th> 
        </tr> 
      </thead> 
    </table>

JS代码:



需要绑定表格时调用AJAX方法,AJAX执行完后会自动调用显示数据方法,表格数据就显示出来了

第二种:直接在前台和JS设置好列名,自动绑定

前台代码:


<table id="dg" class="easyui-datagrid" title="需要显示表格标题 " data-options="         
        rownumbers:true, 
        singleSelect:true, 
        autoRowHeight:false, 
        pagination:true, 
        "> 
        <thead> 
          <tr> 
            <th data-options="field:'colum1',align:'center'">列名1</th> 
            <th data-options="field:'colum2',align:'center'">列名2</th> 
            <th data-options="field:'colum3',align:'center'">列名3</th> 
            <th data-options="field:'colum4',align:'center'">列名4</th> 
            <th data-options="field:'colum5',align:'center'">列名5</th> 
            <th data-options="field:'colum6',align:'center'">列名6</th> 
          </tr> 
        </thead> 
      </table>

JS代码:


把JS代码放在一个function函数中就可以了,函数执行时表格就可以绑定数据了

相关推荐:

深入理解JSON数据源格式_javascript技巧

数据源有哪几种?

详解4种不同形式的数据源配置

以上就是详解EasyUI的DataGrid绑定Json数据源方法的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行