Home>

Old habits, let's start with an effect picture:

1.In ibllAdd a method to get the public model list in the interfacecommonmodelservice interface

Sort method first

///<summary>
  ///sort
  ///</summary>
  ///<param name="entitys">Data entity set</param>
  ///<param name="rodercode">sort code [default:descending id]</param>
  ///<returns></returns>
  iqueryable<commonmodel>order (iqueryable&commonmodel>entitys, int rodercode);
Data query method
///<summary>
  ///Query the paginated data list
  ///</summary>
  ///<param name="totalrecord">Total Records</param>
  ///<param name="model">model [all all]</param>
  ///<param name="pageindex">page number</param>
  ///<param name="pagesize">records per page</param>
  ///<param name="title">Title [Do not use set empty string]</param>
  ///<param name="categoryid">column id [Do not use setting 0]</param>
  ///<param name="inputer">username [do not use set empty string]</param>
  ///<param name="fromdate">start date [may be null]</param>
  ///<param name="todate">due date [may be null]</param>
  ///<param name="ordercode">ordering code</param>
  ///<returns>paging data list</returns>
  iqueryable<commonmodel>findpagelist (out int totalrecord, int pageindex, int pagesize, string model, string title, int categoryid, string inputer, nullable<datetime>fromdate, nullable<datetime>todate, int ordercode);

Bll

Write method implementation code in commonmodelservice,The content is very simple, mainly ideas.
Directly on the code
public iqueryable<commonmodel>findpagelist (out int totalrecord, int pageindex, int pagesize, string model, string title, int categoryid, string inputer, nullable<datetime>fromdate, nullable<datetime>todate, int ordercode)
  {
   //Get entity list
   iqueryable<commonmodel>_commonmodels=currentrepository.entities;
   if (model == null || model!="all") _commonmodels=_commonmodels.where (cm =>cm.model == model);
   if (! string.isnullorempty (title)) _commonmodels=_commonmodels.where (cm =>cm.title.contains (title));
   if (categoryid>0) _commonmodels=_commonmodels.where (cm =>cm.categoryid == categoryid);
   if (! string.isnullorempty (inputer)) _commonmodels=_commonmodels.where (cm =>cm.inputer == inputer);
   if (fromdate!=null) _commonmodels=_commonmodels.where (cm =>cm.releasedate>= fromdate);
   if (todate!=null) _commonmodels=_commonmodels.where (cm =>cm.releasedate<= todate);
   _commonmodels=order (_commonmodels, ordercode);
   totalrecord=_commonmodels.count ();
   return pagelist (_commonmodels, pageindex, pagesize) .asqueryable ();
  }
  public iqueryable<commonmodel>order (iqueryable&commonmodel>entitys, int ordercode)
  {
   switch (ordercode)
   {
    //default sort
    default:
     entitys=entitys.orderbydescending (cm =>cm.releasedate);
     break;
   }
   return entitys;
  }

Web

Because commonmodel is not consistent with the data displayed in our front desk,In order to take care of the data display in the datagrid, another view model commonmodelviewmodel is constructed in ninesky.web.models

using system;
namespace ninesky.web.models
{
 ///<summary>
 ///commonmodel view model
 ///<remarks>
 ///Created:2014.03.10
 ///</remarks>
 ///</summary>
 public class commonmodelviewmodel
 {
  public int modelid {get;set;}
  ///<summary>
  ///column id
  ///</summary>
  public int categoryid {get;set;}
  ///<summary>
  ///program name
  ///</summary>
  public string categoryname {get;set;}
  ///<summary>
  ///model name
  ///</summary>
  public string model {get;set;}
  ///<summary>
  ///title
  ///</summary>
  public string title {get;set;}
  ///<summary>
  ///Entered by
  ///</summary>
  public string inputer {get;set;}
  ///<summary>
  ///click
  ///</summary>
  public int hits {get;set;}
  ///<summary>
  ///Release date
  ///</summary>
  public datetime releasedate {get;set;}
  ///<summary>
  ///status
  ///</summary>
  public int status {get;set;}
  ///<summary>
  ///status text
  ///</summary>
  public string statusstring {get {return ninesky.models.commonmodel.statuslist [status];}}
  ///<summary>
  ///Home picture
  ///</summary>
  public string defaultpicurl {get;set;}
 }
}

Add a jsonlist method in articlecontroller that returns a json type

///<summary>
  ///Article list json [Note the permissions,Is it accessible to ordinary people?】
  ///</summary>
  ///<param name="title">title</param>
  ///<param name="input">entry</param>
  ///<param name="category">column</param>
  ///<param name="fromdate">from date</param>
  ///<param name="todate">date until</param>
  ///<param name="pageindex">page number</param>
  ///<param name="pagesize">records per page</param>
  ///<returns></returns>
  public actionresult jsonlist (string title, string input, nullable<int>category, nullable<datetime>fromdate, nullable<datetime>todate, int pageindex=1, int pagesize=20)
  {
   if (category == null) category=0;
   int _total;
   var _rows=commonmodelservice.findpagelist (out _total, pageindex, pagesize, "article", title, (int) category, input, fromdate, todate, 0) .select (
    cm =>new ninesky.web.models.commonmodelviewmodel ()
    {
     categoryid=cm.categoryid,     categoryname=cm.category.name,     defaultpicurl=cm.defaultpicurl,     hits=cm.hits,     inputer=cm.inputer,     model=cm.model,     modelid=cm.modelid,     releasedate=cm.releasedate,     status=cm.status,     title=cm.title
    });
   return json (new {total=_total, rows=_rows.tolist ()});
  }

Here is the interface,When adding the list method, no data is provided here,Data is obtained in jsonlist

///<summary>
  ///all articles
  ///</summary>
  ///<returns></returns>
  public actionresult list ()
  {
   return view ();
  }

Right click to add a view

<div>
 <div>
  <a href="#" data-options="iconcls:" icon-edit ", plain:true">modify</a>
  <a href="#" data-options="iconcls:" icon-remove ", plain:true" ">delete</a>
  <a href="#" data-options="iconcls:" icon-reload ", plain:true" onclick="$(" #article_list "). Datagrid (" reload ");">Refresh&/a>
 </div>
 <div>
  <label>column</label>
  <label>title</label><input />
  <label>Entered by</label><input />
  <label>add date</label>
  <input type="datetime" />-
  <input type="datetime" />
  <a href="#" data-options="iconcls:" icon-search "">query</a>
 </div>
</div>
<table></table>
<script src="~/scripts/common.js"></script>
<script type="text/javascript">
 $("#article_list"). datagrid ({
  loadmsg:"Loading ...",  pagination:true,  url:"@ url.action (" jsonlist "," article ")",  columns:[[
   {field:"modelid", title:"id", checkbox:true},   {field:"categoryname", title:"column"},   {field:"title", title:"title"},   {field:"inputer", title:"input", align:"right"},   {field:"hits", title:"click", align:"right"},   {field:"releasedate", title:"Release Date", align:"right", formatter:function (value, row, index) {return jsondateformat (value);}},   {field:"statusstring", title:"status", width:100, align:"right"}
  ]],  toolbar:"#toolbar",  idfield:"modelid", });
 //Find
 $("#btn_search"). click (function () {
  $("#article_list"). datagrid ("load", {
   title:$("#textbox_title"). val (),   input:$("#textbox_inputer"). val (),   category:$("#combo_category"). combotree ("getvalue"),   fromdate:$("#datebox_fromdate"). datebox ("getvalue"),   todate:$("#datebox_todate"). datebox ("getvalue")
  });
 });
 }
</script>

The above are the contents of easyui-datagrid.

  • Previous Five Java multi-thread synchronization methods
  • Next 11 ways ASP connects to a database