This project is read-only.

Filter on all columns

Jul 24, 2015 at 11:54 AM
Is there any possibility to filter on all columns?
Jul 24, 2015 at 2:37 PM
I have seen some discussion here on the Grid.MVC Codeplex for doing a Search/Filter on all columns, but the below is what I ended up implementing for my own use via a JQuery call to a Controller Action to perform the Filtering with SearchCriteria, and then returning ("refreshing") my PartialView with the filtered dataset:
// Part of my ~/Home/Index View referencing my PartialView which contains my Grid.MVC component.
<div class="homeContent">

// Code for the Search Bar/Button on my PartialView referenced above.
<input type="text" id="Search" class="searchAllFields" placeholder="Search" /><a class="btn btn-default btn-sm noDecoration"><span id="SearchIcon" onclick="searchAllFields()" class="glyphicon glyphicon-search"></span></a>

// JQuery call to Controller Action when user clicks the magnifying glass icon next to the Searchbox.
    function searchAllFields() {
            url: '@Url.Action("SearchAllColumns", "Home")',
            data: { searchCriteria: document.getElementById("Search").value },
            success: function (resp) {
                // Successful call returns my partial view with newly filtered data.

// Controller Code for the actual Filtering
public ActionResult SearchAllColumns(string searchCriteria)
            var searchResults = db.MODEL_REFERENCE.ToList().Where(m => m.ID.ToString() == searchCriteria ||
                                                        m.NOTE != null && m.NOTE.ToString() == searchCriteria ||
                                                        m.COST != null && m.COST.ToString() == searchCriteria ||
                                                        // ... other fields you wish to filter ... //
                                                        m.DESCRIPTION != null && m.DESCRIPTION.ToString() == searchCriteria ||
                                                        m.CREATED_DATE != null && m.CREATED_DATE.ToString() == searchCriteria ||
                                                        m.CREATED_BY != null && m.CREATED_BY.ToString() == searchCriteria).ToList();
            return PartialView("~/Views/Shared/_homeIndexContent.cshtml", searchResults);
My hope is to refine this, but it's what I have for now. If anyone has any thoughts on improving this please feel free to share here.