layui加载数据

最近项目重构 , 之前用的是jui, 发现不是很理想 , 想来想去 ,还是用了layui , 之前没接触过layui , 一切从0开始 。

首先加载的是table

    <table id="demo" lay-filter="test"></table>

    <script src="~/layui-v2.2.45/layui/layui.js"></script>
    <script>
        layui.use('table', function () {
            var table = layui.table;

            //第一个实例
            table.render({
                elem: '#demo'
                , scrollbar: true
              , url: 'xxxx' //数据url
              , page: true //开启分页
               , edit: true
              , cols: [[ //表头
                     { field: 'StationCode', title: 'xxxx',  "12%", fixed: 'left' }
              
              ]]

            });

 这些代码文档里面都有  很容易找到  注意一点  接口返回的数据格式是固定的  这个一开始不知道  后来还是花了点时间才弄清楚  

   public JsonResult Table(object data, int count, string msg = "成功")
        {
            return Json(new { code = 0, msg = msg, count = count, data = data });//返回的数据格式  固定的  
        }

然后你就会发现数据出来了  ,

layui这个画面风格很不错 ,赏心悦目的, 值得多用 

原文地址:https://www.cnblogs.com/chunxiong/p/8110674.html