Ejemplo n.º 1
0
        /// <summary>
        ///  获取gridtable数据源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sable"></param>
        /// <param name="pars">查询参数</param>
        /// <param name="selectFields">查询字段</param>
        /// <param name="whereObj">参数条件</param>
        /// <returns></returns>
        public static JsonResultModel <T> GetWidgetsSource <T>(Sqlable sable, GridSearchParams pars, string selectFields = "*", object whereObj = null) where T : class
        {
            var    query     = System.Web.HttpContext.Current.Request.QueryString;
            Type   type      = typeof(T);
            string tableName = type.Name;

            sable = sable.Where(BuildQuery(query));
            string orderBy = null;

            if (!string.IsNullOrEmpty(pars.sortorder))
            {
                orderBy = (pars.sortdatafield + " " + pars.sortorder);
            }
            else
            {
                orderBy = "getdate()";
            }
            var rows   = sable.SelectToPageList <T>(selectFields, orderBy, pars.pagenum + 1, pars.pagesize, whereObj);
            var result = new JsonResultModel <T>()
            {
                TotalRows = sable.Count(whereObj),
                Rows      = rows
            };

            return(result);
        }
Ejemplo n.º 2
0
 public JsonResult GetListSourceById(GridSearchParams pars, int whereId)
 {
     if (pars.sortdatafield == null)
         { //默认按id降序
             pars.sortdatafield = "id";
             pars.sortorder = "desc";
         }
         Sqlable sable = ls.GetListSqlable().Where("id=@id");
         var model = JQXGrid.GetWidgetsSource<list>(sable, pars, "*", new { id = whereId });//根据grid的参数自动查询
         return Json(model, JsonRequestBehavior.AllowGet);
 }
Ejemplo n.º 3
0
 public JsonResult GetListSource(GridSearchParams pars)
 {
     if (pars.sortdatafield == null)
     { //默认按id降序
         pars.sortdatafield = "id";
         pars.sortorder = "desc";
     }
     Sqlable sable = ls.GetListSqlable();
     var model = JQXGrid.GetWidgetsSource<list>(sable, pars, "*");//根据grid的参数自动查询
     GC.Collect();
     return Json(model, JsonRequestBehavior.AllowGet);
 }
Ejemplo n.º 4
0
 public JsonResult Data(GridSearchParams pars)
 {
     using (SqlSugarClient db = SugarDao.GetInstance())
     {
         if (pars.sortdatafield == null) { //默认按id降序
             pars.sortdatafield = "id";
             pars.sortorder = "desc";
         }
         Sqlable sable = db.Sqlable().Form<GridTable>("g");//查询表的sqlable对象
         var model = JQXGrid.GetWidgetsSource<Models.GridTable>(sable, pars,"g.*");//根据grid的参数自动查询
         return Json(model, JsonRequestBehavior.AllowGet);
     }
 }