مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

علی اکبر منصوریان

عضویت از 1394/02/27

کار نکردن paging,sorting,filtering در Grid.mvc

  • شنبه 28 شهریور 1394
  • 23:00
تشکر میکنم

با سلام من از grid.mvc در پروژه ام طبق همان اموزشی که در سایت موجود هست از Grid.mvc استفاده کردم، ولی paging,sorting,filtering کار نمی کند. اشکال کارم کجاست با تشکر.

کد وبو:

<link href="@Url.Content("~/Content/Gridmvc.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/bootstrap.min.css")" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/jquery-1.9.1.min.js")"></script>
<script src="@Url.Content("~/Scripts/gridmvc.min.js")"></script>  


@using (Html.BeginForm("Serch", "Serch"))
{

    <div class=" row well" style="align-content:center; margin-top:10px;">
        <div>
            <div class="col-lg-6">
                <div class="input-group">
                    <input type="text" name="search_query" id="search_query"  class="form-control pull-left searchField" value="@ViewBag.serchtext" placeholder="@ViewBag.placeholder">
                    <span class="input-group-btn">
                        <input type="submit" class="btn btn-default " id="Search" value="بگرد!" />
                        @* <input typ="su"  id="btnSerch" type="button"></input>*@
                    </span>

                </div><!-- /input-group -->
            </div><!-- /.col-lg-6 -->
        </div><!-- /.row -->
    </div>
    <div>
        @if (ViewBag.isShow)
        {
            if (ViewBag.isShowText)
            {
                <span class="glyphicon glyphicon-paperclip" style="font-family:Tahoma; font-weight:600; color:blue" /><span style="font-family:Tahoma; color:green">&nbsp;تعداد <b style="color:black;">@ViewBag.count</b> مورد برای جست و جوی عبارت <b style="color:black;">@ViewBag.serchtext</b> پیدا شده است.</span>
            }
            else
            {
                <span class="glyphicon glyphicon-paperclip" style="font-family:Tahoma; font-weight:600; color:blue" /><span style="font-family:Tahoma; color:red">&nbsp; برای جست و جوی عبارت <b style="color:black;">@ViewBag.serchtext</b> هیچ موردی پیدا نشده است.</span>
            }
        }
    </div>

    if (ViewBag.rol == "superadmin")
    {
        if (ViewBag.isShow)
        {
            @Html.Grid(Model).Columns(columns =>
           {
               columns.Add(foo => foo.CategoryTitle).Titled("سازمان").RenderValueAs(o => o.CategoryTitle + " (" + o.CategoryCode + ")").Sortable(true).ThenSortBy(x => x.CategoryCode).ThenSortByDescending(x => x.libCode).ThenSortByDescending(x => x.LevelID).ThenSortByDescending(x => x.PhonNumberTypeTitle).Filterable(true).SetWidth(210);
               columns.Add(foo => foo.libTitle).Titled("معاونت").Sortable(true).Filterable(true);
               columns.Add(foo => foo.LevelTitle).Titled("پست").Sortable(true).Filterable(true);
               columns.Add(foo => foo.Name).Titled("نام و نام خانوادگی").Sortable(true).Filterable(true).RenderValueAs(o => o.Name + " " + o.Family);
               columns.Add(foo => foo.PhonNumberTypeTitle).Titled("نوع شماره تلفن").Sortable(true).Filterable(true);
               columns.Add(foo => foo.Number).Titled("شماره").Sortable(true).Filterable(true);
               columns.Add(foo => foo.IP).Titled("IP مرکز تلفن").Sortable(true).Filterable(true);



           }).Sortable().Filterable().WithPaging(10, 6,"grid_page")

        }
        else
        {

        }

کد کنترلر

[HttpPost]
        public ActionResult Serch(string search_query)
        {
            string[] roleray = new MyProvider().GetRolesForUser(User.Identity.Name);
            string rol = roleray[0];
            var currentuser = db.Users.SingleOrDefault(c => c.UserName == User.Identity.Name);
            var currentPerson = db.Person.Find(currentuser.PersonID);
            var cid = currentPerson.CategoryID;

            var txt = search_query.Trim();
            if (txt == "")
                ViewBag.placeholder = "چیزی برای جست و جو وارد نشده است";
            else
            {
                ViewBag.placeholder = "جست و جو برای ...";
                ViewBag.serchtext = txt;
            }
            List<VW_Full> result = new List<VW_Full>();

            if (!string.IsNullOrEmpty(txt))
            {
                switch (rol)
                {
                    case "superadmin":
                        {
                            result = db.VW_Full.Where(c => c.CategoryTitle.Contains(txt) ||
                   c.CategoryCode.Contains(txt) ||

                   c.libTitle.Contains(txt) ||
                   c.libCode.Contains(txt) ||

                   c.LevelTitle.Contains(txt) ||

                   c.Name.Contains(txt) ||
                   c.Family.Contains(txt) ||

                   c.PhonNumberTypeTitle.Contains(txt) ||
                   c.Number.Contains(txt)

                   ).Distinct().OrderBy(c => c.CategoryCode).ToList();

                            break;
                        }
                    case "admin":
                        {
                            result = (db.VW_Full.Where(d => d.CategoryID == cid).ToList()).Where(c => c.CategoryTitle.Contains(txt) ||
                   c.CategoryCode.Contains(txt) ||

                   c.libTitle.Contains(txt) ||
                   c.libCode.Contains(txt) ||

                   c.LevelTitle.Contains(txt) ||

                   c.Name.Contains(txt) ||
                   c.Family.Contains(txt) ||

                   c.PhonNumberTypeTitle.Contains(txt) ||
                   c.Number.Contains(txt)

                   ).Distinct().OrderBy(c => c.CategoryCode).ToList();

                            break;
                        }
                    case "user":
                        {
                            result = (db.VW_Full.Where(d => d.CategoryID == cid).ToList()).Where(c => c.CategoryTitle.Contains(txt) ||
                  c.CategoryCode.Contains(txt) ||

                  c.libTitle.Contains(txt) ||
                  c.libCode.Contains(txt) ||

                  c.LevelTitle.Contains(txt) ||

                  c.Name.Contains(txt) ||
                  c.Family.Contains(txt) ||

                  c.PhonNumberTypeTitle.Contains(txt) ||
                  c.Number.Contains(txt)

                  ).Distinct().OrderBy(c => c.CategoryCode).ToList();
                            break;
                        }
                    default:
                        break;
                }

                ViewBag.count = result.Count;

                if (result.Count > 0)
                {
                    ViewBag.isShowText = true;

                }
                else
                    ViewBag.isShowText = false;

                ViewBag.isShow = true;
            }
            else
                ViewBag.isShow = false;

            ViewBag.rol = rol.ToString();

            return View("SearchReasult", result);
        }

 

پاسخ های این پرسش

تعداد پاسخ ها : 2 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • یکشنبه 29 شهریور 1394
  • 09:10

اسکریپت ها رو چک کنید

اگر با هم تداخل داشته باشند در بیشتر اوقات Fillter ها , Sort از کار میوفتند

کاربر سایت

saeed3164

عضویت از 1392/04/07

  • پنجشنبه 17 دی 1394
  • 11:24

من میخام Rowindex خودم ایجاد کنم چطوری میشه ایجاد  کرد تو گرید

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)