This is a migrated thread and some comments may be shown as answers.

Filtering is not working

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
minkbear
Top achievements
Rank 1
minkbear asked on 16 Oct 2010, 04:21 AM
As the demo page(http://demos.telerik.com/aspnet-mvc/grid/filtering), I copy code to my project as the page suggest.
But I can not to click filter button next to column header like your demo. So I take a look on HTML of your demo page.
I met your demo page has a below javascript code. and in my page there is no that javascript code.

<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function(){
jQuery('#Grid').tGrid({columns:[{"title":"Order ID","member":"OrderID","type":"Number"},{"title":"Contact Name","member":"ContactName","type":"String"},{"title":"Ship Address","member":"ShipAddress","type":"String"},{"title":"Order Date","member":"OrderDate","type":"Date","format":"{0:MM/dd/yyyy}"}], plugins:["grouping","filtering"], total:830, currentPage:1, sortMode:'single', ajax:{"selectUrl":"/aspnet-mvc/Grid/_FirstLook"}});
 
});
//]]>
</script>

So my question is I have to add the javascript code manually or not?
I actually understand that the javascript code will be generate by Filterable() of your control

Thanks you for your time.

2 Answers, 1 is accepted

Sort by
0
Jigar
Top achievements
Rank 1
answered on 16 Oct 2010, 12:28 PM
hi minkbear,

Can you please post your code here? so can understand your problem.

Regards,

Jigar
0
minkbear
Top achievements
Rank 1
answered on 23 Oct 2010, 05:51 AM
Here are the code.

View:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<CRMDS.Models.ModeofPayment>>" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="sectionTitle">
                    <h2>ModeofPayment</h2>
                    <% using(Html.Configurator("")
                        .PostTo("Filtering", "ModeofPayment")
                        .Begin()) %>
                        <%{ %>
                         
                        <div class="filterWrapper">
                     
                        <%= Html.TextBox("startsWith", "") %>
 
                        <a href="javascript:document.forms[0].submit()" class="smallButton"><span><i class="iconSearch">search</i></span></a>
                         
                        </div>
                    <%} %>
                    <div class="clearboth"></div>
</div>
 
<div class="dataTableWrapper">
<%  int[] checkedRecords = (int[])ViewData["checkedRecords"];
    Html.Telerik().Grid(Model)
        .Name("Grid")
        .ToolBar(commands => commands
            .Custom()
            .Text("Add")
            .Action("Create", "ModeofPayment")
            .HtmlAttributes(new { @class = "iconAdd" })
        )
        .ToolBar(commands => commands
            .Custom()
            .Text("Delete")
            .Action("MultiDelete", "ModeofPayment")
            .HtmlAttributes(new { @class = "iconDelete" })
        )
        .Columns(columns =>
        {
            columns.Template(o =>
            {
                %>
                <input name="checkedRecords" type="checkbox" value="<%= o.ModeofPaymentId %>"
                <% if (checkedRecords.Contains(o.ModeofPaymentId)) {%>
                checked="checked"
                <% } %>
                />
                <%
            }).Title("")
                .Width(30)
                .HtmlAttributes(new { style = "text-align:center" });
            columns.Bound(o => o.ModeofPaymentId)
                    .Width(30)
                    .Title("")
                    .Sortable(false)
                    .Filterable(false)
                    .HtmlAttributes(new { style = "text-align:center" })
                    .Template(o =>
            {
                 %> <a href='../ModeofPayment/Edit/<%= o.ModeofPaymentId%>' class='iconEdit'></a> <%
            });
            columns.Bound(o => o.NameEng).Width(200);
            columns.Bound(o => o.NameLocal);
        })
        .Pageable(pager => pager.PageSize(int.Parse(System.Configuration.ConfigurationManager.AppSettings["MasterDataPageSize"])))
        .Sortable()
        .Filterable()
        .Render();
%>
</div>
</asp:Content>

Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CRMDS.Models;
using Web.Infrastructure.Storage;
using Telerik.Web.Mvc;
 
namespace CRMDS.Controllers
{
    public partial class ModeofPaymentController : Controller
    {
        const int PageSize=20;
        ISession _session;
        public ModeofPaymentController(ISession session)
        {
            _session = session;
        }
 
        public virtual ActionResult Index(int[] checkedRecords)
        {
            checkedRecords = checkedRecords ?? new int[] { };
            ViewData["checkedRecords"] = checkedRecords;
 
            var items = _session.All<ModeofPayment>().OrderByDescending(x => x.CreatedOn);
            var list = new PagedList<ModeofPayment>(items, 0, PageSize);
            return View(items);
        }
 
        public virtual ActionResult AjaxBindingModeofPayment(bool? filtering)
        {
            var items = _session.All<ModeofPayment>().OrderByDescending(x => x.CreatedOn);
            var list = new PagedList<ModeofPayment>(items, 0, 10);
            ViewData["filtering"] = filtering ?? true;
            return View(new GridModel(list));
        }
 
        [GridAction]
        public virtual ActionResult _AjaxBindingModeofPayment()
        {
            var items = _session.All<ModeofPayment>().OrderByDescending(x => x.CreatedOn);
            var list = new PagedList<ModeofPayment>(items, 0, 10);
            return View(new GridModel(list));
        }
 
        public ActionResult Filtering(string startsWith)
        {
            ViewData["checkedRecords"] = new int[] { };
            ViewData["startsWith"] = startsWith ?? null;
 
            var items = _session.All<ModeofPayment>();
 
            if (!String.IsNullOrEmpty(startsWith))
                items = items.Where<ModeofPayment>(x => x.NameEng.StartsWith(startsWith));
 
            items = items.OrderByDescending(x => x.CreatedOn);
             
            var list = new PagedList<ModeofPayment>(items, 0, PageSize);
            return View("Index", items);
        }
 
        [GridAction]
        public ActionResult _Filtering()
        {
            var items = _session.All<ModeofPayment>().OrderByDescending(x => x.CreatedOn);
            var list = new PagedList<ModeofPayment>(items, 0, PageSize);
            return View(items);
        }
    }
}
Tags
Grid
Asked by
minkbear
Top achievements
Rank 1
Answers by
Jigar
Top achievements
Rank 1
minkbear
Top achievements
Rank 1
Share this question
or