基于layui方法渲染表格的C#后端实现

本次主要实现前端采用layui的方法渲染方式,后端使用C#代码实现的方法。直接上代码

前端代码

html代码

 <div class="layui-card-body">
            <table id="test" lay-filter="test"></table>
  </div>

js代码

table.render({
                elem: '#test'
                , title: 'worktime'
                , size: 'lg'
                , id: 'test'
                , limit: 150
                , cols: [[
                    { field: 'title', title: '文件名', width: '20%', fixed: 'left', edit: false, sort: false },
                    { field: 'url', title: '路径', width: '20%', sort: false },
                    { field: 'desc', title: '描述', width: '20%', sort: false },
                    { field: 'uploadtime', title: '上传时间', width: '20%', sort: false },
                    { field: 'updatetime', title: '更新时间', width: '20%', sort: false },
                ]]
  });

核心ajax代码部分

//获取输入数据
                    var startTime = $("#datetime1").val();
                    var endTime = $("#datetime2").val();
                    var fileName = $("#fileName").val();
                    $.ajax({
                        url: "@Href("~/FirstPage/queryFileTable")",
                        async: false,
                        data: { "startTime": startTime, "endTime": endTime, "fileName": fileName},
                        type: "GET",
                        dataType: "json",
                        success: function (data) {
                            console.log('获取到后端返回的值:');
                            console.log('data', data);
                            if (data.code == '200') {
                                table.reload('test', { data:data.data });
                            }
                            else
                            {
                                layer.msg('获取数据失败');
                            }
                        },
                        error: function (response, ajaxOptions, thrownError) {
                            console.log('response', response);
                            console.log('ajaxOptions', ajaxOptions);
                            console.log('thrownError', thrownError);
                        }
                    });

后端核心C#代码

控制层代码

public class FirstPageController : Controller
{

       public string queryFileTable()
        {
            DateTime beginTime=DateTime.Now;
            DateTime endTime =DateTime.Now;
            string b= Request["startTime"].ToString();
            string e =Request["endTime"].ToString();
            string fileName = Request["fileName"].ToString();
            bool isB = false;
            bool isE = false;
            if (b!= null && b != "")
            {
                beginTime = Convert.ToDateTime(b);
                isB = true;
            }
            if (e != null && e != "")
            {
                endTime = Convert.ToDateTime(e);
                isE = true;
            }
            if (!isB &&!isE)
            {
                //则使用时间段和文件名查询
                ResponesData res = new ResponesData();
                try
                {
                    res.data = new FileDAL().findFilebyName(fileName);
                    res.code = "200";
                    res.count = "2";
                }
                catch (Exception ex)
                {
                    log.Info("报错了.......");
                    log.Error(ex);
                    res.code = "500";
                }
                return JsonConvert.SerializeObject(res);//返回核心语句
            }
            else
            {
                return null;
            }
        } 

}

//业务层代码

public class FileDAL
    {

        //按照文件名查询
        public List<FileInfo> findFilebyName(string name)
        {
            string sql =string.Format("SELECT a.title,a.url,b.`desc`,b.uploadtime,b.updatetime from minfo a, nodedesc b where a.id = b.nodeId and a.title like '%{0}%'",name);
            DataTable d = MySQLHelper.GetDataTable(sql);//执行sql语句
            List<FileInfo> l = new List<FileInfo>();
            l = common.TableToList<FileInfo>(d);//将查询得到的table转成list集合类型
            return l;//返回集合类型
        }

}

ResponesData代码

public class ResponesData
    {
        private string Code;

        public string code
        {
            get { return Code; }
            set { Code = value; }
        }
        private string Msg;

        public string msg
        {
            get { return Msg; }
            set { Msg = value; }
        }
        private string Count;

        public string count
        {
            get { return Count; }
            set { Count = value; }
        }
        private object Data;

        public object data
        {
            get { return Data; }
            set { Data = value; }
        }

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值