Using onRowSelect to filter another grid

Feb 5, 2015 at 1:25 PM
I trying to use the onRowSelect of one grid to filter another grid .

Here is the relevant code:

Index.cshtml
@using GridMvc.Html
@using GridMvc.Sorting
@using MockupWebsite.Models;
@model ActiveFieldingsGridData

@{
    ViewBag.Title = "Home Page";
}

@*<div class="jumbotron">*@
    @*<h1>ASP.NET</h1>*@
    @*<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
    <p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>*@
    @*<p class="lead">IUID Mobile Fieldings</p>*@
@*</div>*@

<div class="row">
    <div class="col-md-4">
        @*<h2>Getting started</h2>
                <p>
                    ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
                    enables a clean separation of concerns and gives you full control over markup
                    for enjoyable, agile development.
                </p>
                <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
            </div>
            <div class="col-md-4">
                <h2>Get more libraries</h2>
                <p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
                <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
            </div>
            <div class="col-md-4">
                <h2>Web Hosting</h2>
                <p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
                <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
            </div>*@
        <h3>Active Fieldings</h3>
        @{
            Html.RenderPartial("_ActiveFielding", Model.Grid);
        }

    </div>
    <div class="col-md-4">
        <h3>Fielding Types</h3>
        @{
            Html.RenderPartial("_FieldingItemType", Model.Grid2);
        }
    </div>
</div>

@section scripts
{
    <script type="text/javascript">
        $(document).ready(function() {
            $(function () {
                pageGrids.activeFieldings.onRowSelect(function (e) {
                    $.ajax({
                        type: "GET",
                        dataType: 'html',
                        url: '@Url.Action("Index", "Home")',
                        data: {
                            UIC_ID: e.row.UIC_ID,
                        },
                        success: function (data) {
                            $('#fieldingItemTypes').html(data);

                        },
                        error: function (xhr, ajaxOptions, thrownError) {alert(thrownError);}

                    });
                });
            });
        });

    </script>
}
_ActiveFielding.cshttml
@using GridMvc.Html
@using GridMvc.Sorting
@using MockupWebsite.Models;
@model Grid.Mvc.Ajax.GridExtensions.AjaxGrid<Fielding>

@Html.Grid(Model).Named("activeFieldings").Columns(columns =>
    {
        columns.Add(c => c.UIC_ID, true);
        columns.Add(c => c.UIC).Titled("UIC").SetWidth(80).Encoded(false).Sanitized(false).SortInitialDirection(GridSortDirection.Descending);
        columns.Add(c => c.UNIT_DESCRIPTION).Titled("UNIT NAME").SetWidth(200).Encoded(false).Sanitized(false).SortInitialDirection(GridSortDirection.Descending);
    }).Sortable(true).WithPaging(10).Filterable().WithMultipleFilters()
_FieldingItemType.cshtml
@using GridMvc.Html
@using GridMvc.Sorting
@using MockupWebsite.Models;
@model Grid.Mvc.Ajax.GridExtensions.AjaxGrid<FieldingItemType>

@Html.Grid(Model).Named("fieldingItemTypes").Columns(columns =>
{
     columns.Add(c => c.ITEM_TYPE_ID, true);
     columns.Add(c => c.DOCUMENT_NUMBER).Titled("DOCUMENT NUMBER").SetWidth(140).Encoded(false).Sanitized(false).SortInitialDirection(GridSortDirection.Descending);
     columns.Add(c => c.LIN).Titled("LIN").SetWidth(50).Encoded(false).Sanitized(false).SortInitialDirection(GridSortDirection.Descending);
     columns.Add(c => c.NSN).Titled("NSN").SetWidth(100).Encoded(false).Sanitized(false).SortInitialDirection(GridSortDirection.Descending);
     columns.Add(c => c.QUANTITY).Titled("QUANTITY").SetWidth(30).Encoded(false).Sanitized(false).SortInitialDirection(GridSortDirection.Descending);
    columns.Add(c => c.STATUS).Titled("STATUS").SetWidth(100).Encoded(false).Sanitized(false).SortInitialDirection(GridSortDirection.Descending);
}).Sortable(true).WithPaging(10).Filterable().WithMultipleFilters()
Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MockupWebsite.Models;
using Grid.Mvc.Ajax.GridExtensions;


namespace MockupWebsite.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index(Nullable<int> UIC_ID)
        {
            AjaxGrid<FieldingItemType> afigrid = null;
            var fieldings = new ActiveFieldings().AsQueryable();
            var afgrid = (AjaxGrid<Fielding>)new AjaxGridFactory().CreateAjaxGrid(fieldings, 1, false);
            var fieldingtypes = new FieldingItemTypes();
            if (fieldings.Count() > 0)
            {
                if (UIC_ID.HasValue)
                {
                    Fielding fld = (from f in fieldings where f.UIC_ID == UIC_ID.Value select f).FirstOrDefault();
                    afigrid = (AjaxGrid<FieldingItemType>)new AjaxGridFactory().CreateAjaxGrid(fieldingtypes.FilterByFielding(fld), 1, false, 10);
                }
                else
                {
                    afigrid = (AjaxGrid<FieldingItemType>)new AjaxGridFactory().CreateAjaxGrid(fieldingtypes.FilterByFielding(fieldings.First()), 1, false, 10);
                }
            }
            else
            {
                afigrid = (AjaxGrid<FieldingItemType>)new AjaxGridFactory().CreateAjaxGrid(new List<Fielding>().AsQueryable(), 1, false, 10);
                
            }
            return View(new ActiveFieldingsGridData() { Grid = afgrid, Grid2 = afigrid });
        }
        
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
All the code runs o.k. but the fieldingItemTypes grid does not update.