Click here to Skip to main content
15,891,204 members
Articles / Programming Languages / C#
Tip/Trick

Section 3: JQGrid and MVC Demo with Custom Filters or Search Functionality

Rate me:
Please Sign up or sign in to vote.
4.76/5 (9 votes)
3 Oct 2014CPOL2 min read 65.3K   17   13
JQGrid and MVC Demo with Custom Filters or Search Functionality

Sections 1 & 2: ASP.NET MVC-4, Entity Framework and JQGrid Demo with simple Todo List WebApplication

Section 3: JQGrid and MVC Demo with Custom Filters or Search Functionality

Overview

Let us see how to implement the Custom Filters or Search functionality in "TodoList JQGrid MVC sample application".

Source Code

You can download the source code from https://jqgridsearchfilter.codeplex.com.

Search functionality in JQGrid can be implemented in 2 ways:

  1. Client Side Search functionality (Built in JQGrid Feature).

    Video: https://www.youtube.com/watch?v=5w2ycpN2jss

  2. Server Side Search functionality (Custom Filters)

    Video: https://www.youtube.com/watch?v=gPMwsC1PBFA

1. Client Side Search Functionality (Built in JQGrid Feature)

There are 2 steps to implement the JQGrid Built in Search functionality from the client side.

Step 1: Add "loadonce" property to JQGrid and set it to true.

Step 2: Set "search" property to true in navGrid method.

Note: Disadvantage of using this approach is pagination functionality will be disabled, since "loadonce" property is set to true. So we have to load all the records at once. And the search functionality will be performed by the JQGrid on the Client side itself.

Image 1

Image 2

2. Server Side Search Functionality (Custom Filters)

  • Set "loadonce" property to false present in the "TodoList.js" file.
  • Open TodoList "Index.cshtml" page and add the required filters.

    Image 3

    Image 4

  • 3 fields, namely Task Name, Severity and Target date is added has a filter.
  • 1 Search button is added for filtering the data.
  • A class with name "filterItem" has been added in all the 3 fields.
  • Open "TodoList.js" page.
  • Add a jquery click functionality in Document.Ready Function() to post the filter values to the controller and reload the JQGrid.

    Image 5

  • Open "TodoListController" and add additional required filter parameters.
  • Also handle the Searchfunctionality with the help of Linq Queries based on the condition, i.e., value present in the parameters that are received.

    Image 6

  • So finally, we have implemented the custom search functionality on the server side.

    Image 7

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer HP
India India
I am working in HP as a dot net developer.Working in .net technologies(MVC,Entityframework,LINQ,Jquey

Comments and Discussions

 
GeneralMy vote of 5 Pin
Member 410934416-Sep-23 4:17
Member 410934416-Sep-23 4:17 
QuestionSearch with viewmodel Pin
Member 1187650113-Mar-16 3:06
Member 1187650113-Mar-16 3:06 
QuestionThe filter functionality not working Pin
CHETYA2884-Oct-15 23:53
CHETYA2884-Oct-15 23:53 
QuestionI have this demo with Entity Framework using visual studio 2013 Pin
Akshay Banokar5-Apr-15 0:49
Akshay Banokar5-Apr-15 0:49 
QuestionWe are using filter option is ToolBar. How to disable operators which are not relevant to that datatype Pin
Member 466369631-Mar-15 20:21
Member 466369631-Mar-15 20:21 
GeneralGreat Tutorial Pin
tj.power8-Oct-14 5:42
tj.power8-Oct-14 5:42 
GeneralRe: Great Tutorial Pin
Dileep Ashok8-Oct-14 20:07
professionalDileep Ashok8-Oct-14 20:07 
QuestionjqGrid is poorly documented and difficult to use. Pin
sobo1237-Oct-14 9:31
sobo1237-Oct-14 9:31 
jqGrid is poorly documented and difficult to use.
AnswerNo its pretty easy only, compared to slick grid. We are using from last 3 years Pin
Dileep Ashok7-Oct-14 22:13
professionalDileep Ashok7-Oct-14 22:13 
QuestionImages are offsite Pin
Nelek5-Oct-14 10:29
protectorNelek5-Oct-14 10:29 
AnswerRe: Images are offsite Pin
Dileep Ashok6-Oct-14 2:51
professionalDileep Ashok6-Oct-14 2:51 
GeneralMy Vote 5 Pin
Shemeemsha (ഷെമീംഷ)3-Oct-14 17:46
Shemeemsha (ഷെമീംഷ)3-Oct-14 17:46 
GeneralRe: My Vote 5 Pin
Dileep Ashok6-Oct-14 2:49
professionalDileep Ashok6-Oct-14 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.