随笔 - 435  文章 - 0  评论 - 111  阅读 - 62万 

后端

复制代码
        public ActionResult ListByPage1(int start = 0, int length = 10)
        {
            string value = Request.Query["search[value]"];
            string sortColumnIndex =  Request.Query["order[0][column]"];
            string sortField = Request.Query["columns["+ sortColumnIndex + "][data]"];
            string direction = Request.Query["order[0][dir]"];
            string orderBy = sortField + " " + direction;
            string SysId = 1string sql = "select  * from Announcement where isActive=1 and SysId={0} and Subject like {1}";
            //不能用字符串拼接,否则会出警告
            var qry = _context.Announcements.FromSql(sql, new[] { SysId, '%' + value + '%' }).OrderBy(orderBy);
            IQueryable<Announcement> list;
            //jquery.datatable用start,length

             list = qry.Skip(start).Take(length);
 

            var result = new { total = qry.Count(), rows = list.ToList() };


            return Json(result);
        }
复制代码

JS

复制代码
<!-- page script -->
<script>
    $(function () {

        $('#example2').DataTable({
            "processing": true,
            "serverSide": true,
            ajax: {
                url: '/@controller/ListByPage1',
                dataSrc: 'rows',
                dataFilter: function (data) {
                    var json = jQuery.parseJSON(data);
                    json.recordsTotal = json.total;
                    json.recordsFiltered = json.total;
                    json.data = json.rows;

                    return JSON.stringify(json); // return JSON string
                }
            },
            columns: [
                { data: 'subject' },
                { data: 'createDate' },
                { data: 'modifyDate' }
            ],
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true, // 是否显示情报 就是"当前显示1/100记录"这个信息
            "autoWidth": false,
        });
    });
    $.fn.dataTable.defaults.oLanguage = {
        "sProcessing": "处理中...",
        "sLengthMenu": "显示 _MENU_ 项结果",
        "sZeroRecords": "没有匹配结果",
        "sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
        "sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
        "sInfoPostFix": "",
        "sSearch": "搜索:",
        "sUrl": "",
        "sEmptyTable": "表中数据为空",
        "sLoadingRecords": "载入中...",
        "sInfoThousands": ",",
        "oPaginate": {
            "sFirst": "首页",
            "sPrevious": "上页",
            "sNext": "下页",
            "sLast": "末页"
        },
        "oAria": {
            "sSortAscending": ": 以升序排列此列",
            "sSortDescending": ": 以降序排列此列"
        }
    }


</script>
复制代码

HTML

复制代码
<table id="example2" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>@Html.Lang("lblSubject")</th>
            <th>@Html.Lang("lblCreateDate")</th>
            <th>@Html.Lang("lblModifyDate")</th>
        </tr>
    </thead>
</table>
复制代码

 

posted on   Gu  阅读(250)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
历史上的今天:
2019-03-04 EasyUI的textbox的disable ,readonly 用法
2019-03-04 EasyUI 中 Combobox里的onChange和onSelect事件的区别
2012-03-04 Collation conflict occur at operation on User define funtion & table's column
点击右上角即可分享
微信分享提示