Loading Grid

Dec 1, 2014 at 10:52 AM
Hi There,

I'm trying to bind my grid to the values from a couple of drop down boxes, my 'GetItems' function in the controller accepts two parameters and then returns the data back to my main page fine.

My problem is how do I get these values to appear in my grid? I've tried using the what I think is used in the demo javascript:
But I get a runtime error saying its "unable to get property 'load' of undefined or null reference"

Any thoughts on what I'm doing wrong? The data is been passed back from the controller fine I just don't think the grid is refreshing?

My javascript function is below:
$(document).ready(function() {
        $('#availablemonths').on('change', function () {
            var PID = $('#portfolio').val();
            var MONTH = $('#availablemonths').val();

                type: "GET",
                dataType: 'html',
                url: '@Url.Action("GetItems", "PortfolioValuation")/',
                data: {
                    PortfolioID: PID,
                    PortfolioValueDate: MONTH
                success: function (data) {
                   function setContent(o) {
                        if (!o.Cfg.LoadOnParentChange) {$('#FundGrid').data('api').load();}
                error: function (xhr, ajaxOptions, thrownError) { alert(thrownError); }
                //dataType: 'html',});
and my grid:
    new Column { Name = "FundName", PercentWidth = 40, Header = "Fund Name", Sort = Sort.Asc },
    new Column { Name = "OpeningMV", PercentWidth = 25, Header = "Opening MV", ClientFormatFunc = "formatOpen" },
    new Column { Name = "CurrentMV", PercentWidth = 25, Header = "Closing MV", ClientFormatFunc = "formatClose" },
    new Column { Name = "Ret", PercentWidth = 10, Header = "Return", ClientFormatFunc = "formatPercent" }
                   ).Url(Url.Action("GetItems", "PortfolioValuation", Model.PortfolioID)
                            ).Parent("portfolio", "PortfolioID").Parent("availablemonths", "PortfolioValueDate").LoadOnParentChange(true)
Dec 1, 2014 at 12:07 PM
Edited Dec 1, 2014 at 12:08 PM
you're getting "unable to get property 'load' of undefined or null reference" because
there's no "Grid" but "FundGrid" so you need $('#FundGrid').data('api')

but I think that you probably don't event need to use the api

because you're using .Parent

have a look at the code of the first grid from here http://demo.aspnetawesome.com

when the value of the parent changes the grid will reload itself, note parent is Parent(htmlId, paramName), so first parameter is the html id second, is the parameter name in the grid controller action ( use Ctrl+Shift+Space in VS, there's xml docs available)

and Sortable(true) are defaults so no need to specify,
Marked as answer by ChrisAllison on 12/1/2014 at 4:35 AM
Dec 1, 2014 at 12:38 PM
Thanks O

I removed the javascript call and I think my controller action result wasn't a HttpPost type function which is what the grid is expecting, changed that fixed my url code and it worked!
Dec 1, 2014 at 12:52 PM
HttpPost attribute on the action is not required,
you can use post requests for get grid actions