Controller
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[HttpPost] public JsonResult veriSayfalama() { int draw = Convert.ToInt32(Request.Form["draw"]);// etkin sayfa numarası int start = Convert.ToInt32(Request["start"]);//listenen ilk kayıtın index numarası int length = Convert.ToInt32(Request["length"]);//sayfadaki toplam listelenecek kayit sayısı string search = Request["search[value]"];//arama string sortColumnName = Request["columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]"];//Sıralama yapılacak column adı string sortDirection = Request["order[0][dir]"];//sıralama türü List<isler> model = new List<isler>(); using (DBModel db = new DBModel()) { model = db.isler.ToList(); if(!string.IsNullOrEmpty(search))//filter { model = model.Where(x => x.YapilanIs.Contains(search)).ToList(); } int FiltrelenmisKayitSayisi = model.Count; //short model = model.OrderBy(sortColumnName + " " + sortDirection).ToList(); //paging model = model.Skip(start).Take(length).ToList(); int toplamKayit = db.isler.Count(); return Json(new { data = model, draw = Request["draw"], recordsTotal = toplamKayit, recordsFiltered = FiltrelenmisKayitSayisi}); } return Json(""); } |
|
1 |
model = model.OrderBy(sortColumnName + " " + sortDirection).ToList(); |
Sıralama yaparken dinamik sorgu kullanılmıştır. aşağıdaki nuget paketi projenize dahil ediniz.
|
1 |
Install-Package System.Linq.Dynamic -Version 1.0.7 |
View
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
@{ Layout = null; } <link href="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet" /> <div class="row"> <div class="col-lg-12" style="background-color: white; padding: 15px;"> <table id="myTable" class="table table-striped table-bordered" style="width:100%"> <thead> <tr> <th>ad</th> <th>Yapılan İş</th> <th>Süre</th> <th>Kategori</th> <th>Tarih</th> </tr> </thead> </table> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $('#myTable').DataTable({ "ajax": { "url": "/home/veriSayfalama", "type": "POST", "datatype":"json" }, "columns": [ { "data": "Isim", "name": "Isim", "autoWidth": true }, { "data": "YapilanIs", "name": "YapilanIs", "autoWidth": true }, { "data": "IsSure", "name": "IsSure", "autoWidth": true }, { "data": "YapilanIsKategori", "name": "YapilanIsKategori", "autoWidth": true }, { "data": "Tarih", "name": "Tarih", "autoWidth": true } ], "serverSide": "true", "order": [0, "asc"], "processing": "true", "language": { "processing":"Yükleniyor... Lütfen Bekleyin" } }); }); </script> |
Class
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public partial class isler { [Required] [StringLength(50)] public string Isim { get; set; } [Required] [StringLength(16777215)] public string YapilanIs { get; set; } [Required] [StringLength(75)] public string IsSure { get; set; } [Required] [StringLength(45)] public string YapilanIsKategori { get; set; } [Column(TypeName = "date")] public DateTime Tarih { get; set; } } |
Teşekkürler Ahmet Bey.
Rica ederim iyi çalışmalar.