MVC4 filter on custom parent GRID table value

3 posts, 0 answers
  1. Dmitriy
    Dmitriy avatar
    2 posts
    Member since:
    Jul 2013

    Posted 26 Jul 2013 Link to this post

    Hi,

    I'm trying to filter on value from parent GRID  (dynamically)  
    .Filter(filter => filter.Add(prod => prod.COUNTER_PRNITER_ID).IsEqualTo(decimal.Parse("# =PRINTER_ID#")))
    But he try to parse the string not the value of printer id

    the COUNTER_PRNITER_ID is the Forgen KEY of the PRINTER_ID (Parent KEY)

    I want to show in the second GRID only the data that belong to selected printer
    Kan somebody help me?

    Thanks in advance
    Dmitriy Utsmiyev

    Sample code below

     @(Html.Kendo().Grid((IEnumerable<KendoUIMvcLoginApp.Models.Data.Printer>)ViewBag.Printers)
                .Name("grid")
                .Columns(columns =>
                {
                    columns.Bound(e => e.PRINTER_NAME).Title("Printer Name");
                    columns.Bound(e => e.PRINTER_IP).Hidden();
                    columns.Bound(e => e.PRINTER_ID).Hidden();
                    columns.Bound(e => e.PRINTER_MIB_ID).Hidden();
                   
                    columns.Command(command => command.Custom("Start").Click("showDetails")).Width(50);
                })
                .ClientDetailTemplateId("template")
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("HierarchyBinding_Employees", "Grid"))
                )
                .Events(events => events.DataBound("dataBound"))
            )
       
            <script id="template" type="text/x-kendo-template">
                @(Html.Kendo().TabStrip()
                        .Name("tabStrip_#=PRINTER_ID#")
                        .SelectedIndex(0)
                        .Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
                        .Items(items =>
                        {  
                            items.Add().Text("Test Counters").Content(@<text>
                                @(Html.Kendo().Grid((IEnumerable<KendoUIMvcLoginApp.Models.Data.Counter>)ViewBag.Counters)
                                    .Name("grid_#=PRINTER_ID#")
                                    .Columns(columns =>
                                    {
                                        columns.Bound(o => o.COUNTER_NAME).Title("Name");
                                        columns.Bound(o => o.COUNTER_VALUE).Title("Value");
                                        columns.Bound(o => o.COUNTER_PRICE).Title("Price");
                                        columns.Bound(o => o.COUNTER_PRICE_TOTAL).Title("Total Price");
                                        columns.Bound(o => o.COUNTER_PRNITER_ID).Title("ID");
                                    })
                                    .DataSource(dataSource => dataSource
                                        .Ajax()
                                        .Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=PRINTER_ID#" }))
                                        .Filter(filter => filter.Add(prod => prod.COUNTER_PRNITER_ID).IsEqualTo(decimal.Parse("# =PRINTER_ID#")))
                                 )
                                    .Sortable()
                                    .ToClientTemplate())
                            </text>
                            );
                            items.Add().Text("Printer Information").Content(
                                "<div class='employee-details'>" +
                                    "<ul>" +
                                        "<li><label>Printer:</label>#= PRINTER_NAME #</li>" +
                                        "<li><label>Ip address:</label>#= PRINTER_IP #</li>" +
                                        "<li><label>ID:</label>#= PRINTER_ID #</li>" +
                                        "<li><label>MIB:</label>#= PRINTER_MIB_ID #</li>" +
                                    "</ul>" +
                                "</div>"
                            );
                        })
                        .ToClientTemplate())
            </script>        <script>
                function dataBound() {
                    this.expandRow(this.tbody.find("tr.k-master-row").first());
                }
            </script>
             <script>
                function dataBound() {
                    this.expandRow(this.tbody.find("tr.k-master-row").first());
                }
            </script>
            <style scoped="scoped">
                .k-detail-cell .k-tabstrip .k-content {
                    padding: 0.2em;
                }
                .employee-details ul
                {
                    list-style:none;
                    font-style:italic;
                    margin: 15px;
                    padding: 0;
                }
                .employee-details ul li
                {
                    margin: 0;
                    line-height: 1.7em;
                }            .employee-details label
                {
                    display:inline-block;
                    width:90px;
                    padding-right: 10px;
                    text-align: right;
                    font-style:normal;
                    font-weight:bold;
                }
            </style>
  2. Dmitriy
    Dmitriy avatar
    2 posts
    Member since:
    Jul 2013

    Posted 26 Jul 2013 Link to this post

    I have found also the following:


    .Filter(filter => filter.Add(prod => prod.COUNTER_PRNITER_ID).IsEqualTo(((KendoUIMvcLoginApp.Models.Data.Printer)(this.Ajax.ViewContext.ViewData.Model)).PRINTER_ID) )

    but in this case i can see only the last id of my PRINTE_ID
    i think it because the data of the first GRID is already posted

  3. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2193 posts

    Posted 30 Jul 2013 Link to this post

    Hi Dmitriy,

     
    Please note that we already provide such example in our CodeLibrary which demonstrates how to configure Grid Ajax to filter the child grid data:


    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top