zoukankan      html  css  js  c++  java
  • c# .net core List分页加排序

                    int total = 0;
    //获取数据总数 total
    = result.Count(); //判断是否需要排序if (!string.IsNullOrEmpty(real.sortName) && (!real.sortType.ToLower().Equals("desc") || !real.sortType.ToLower().Equals("asc"))) {
    //自定义接收数据实体类 List
    <Returnlist> infoList = result.Skip((real.pageIndex - 1) * real.pageSize).Take(real.pageSize).ToList(); infoList.Sort( delegate (Returnlist info1, Returnlist info2) { Type t1 = info1.GetType(); Type t2 = info2.GetType(); PropertyInfo pro1 = t1.GetProperty(real.sortName); PropertyInfo pro2 = t2.GetProperty(real.sortName); string clType = pro1.PropertyType.ToString();
                     //判断类型为数字使用数字排序,其他使用string排序
    if (clType == "System.Decimal" || clType == "System.Int" || clType == "System.Int32" || clType == "System.Int64" || clType == "System.Double") { decimal info1val = Convert.ToDecimal(pro1.GetValue(info1, null)); decimal info2val = Convert.ToDecimal(pro2.GetValue(info2, null)); return real.sortType.ToLower().Equals("asc") ? info1val.CompareTo(info2val) : info2val.CompareTo(info1val); } else { return real.sortType.ToLower().Equals("asc") ? pro1.GetValue(info1, null).ToString().CompareTo(pro2.GetValue(info2, null).ToString()) : pro2.GetValue(info2, null).ToString().CompareTo(pro1.GetValue(info1, null).ToString()); } }); returnResult = new ReturnResult() { list = infoList, total = total, message = "成功" }; } else { returnResult = new ReturnResult() { list = result.Skip((real.pageIndex - 1) * real.pageSize).Take(real.pageSize).ToList(), total = branchAL.Count(), message = "成功" }; }
  • 相关阅读:
    sharding-jdbc精确分片配置
    sharding-jdbc注意事项
    sharding-jdbc绑定表和公共表
    go 语言解析yaml文件作为配置文件
    go语言添加全局的json配置文件
    go查询数据库讲单数据结果绑定结构体
    sharding-jdbc分库分表节点路由
    增强for循环对遍历的集合进行增删改操作会出现并发修改异常
    go语言数据模型改变响应给前端字段名
    视图
  • 原文地址:https://www.cnblogs.com/provedl/p/13594401.html
Copyright © 2011-2022 走看看