joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
74 stars 55 forks source link

Can't post question on Stack Overflow #13

Closed johnpreed closed 9 years ago

johnpreed commented 9 years ago

Stack Overflow won't let me post my question because the tag "mvcgrid.net" is not an existing tag and I don't have 1500 reputation yet to create it. Sorry if this is the wrong forum for this. If you can create the tag i'll happily post this to SO.

I'll post my issue below:

I'm using MVCGrid.net (http://mvcgrid.net). First of all, fantastic grid tool! I have my grid working properly, however when i'm populating my grid I need to pass an additional parameter to my RetrieveDataMethod. The value i need to pass is part of my view model and I'm pretty sure I need to pass it as an AdditionalQueryOption. I don't want this to be a filter because i don't want it only sent after a client side event. I want it passed to my RetrieveDataMethod always. i tried adding data-mvcgrid-type='additionalQueryOption' to my hidden input, and it still wasn't sent. Then i noticed that this requires data-mvcgrid-apply-additional='event' to trigger the event. how is this different than a filter? Is there a grid loading event that i can hook into to register my hidden value as an additional query option? What's the right approach for my situation here?

Here's my Retrieve Data Method definition for my grid:

.WithRetrieveDataMethod((context) =>
{
    var options = context.QueryOptions;

// this is the bit i need var projectId = ???; options.AdditionalQueryOptions.Add("projectId", projectId);

    int totalRecords;
    var items = ReportManager.GetReports(out totalRecords, options);

    return new QueryResult<ReportSummaryViewModel>()
    {
        Items = items,
        TotalRecords = totalRecords
    };
})

This is the View Code:

<h1>Reports for @Model.ProjectName</h1>

<p class="form-inline">
    <button type="button" class="btn btn-default" onclick="window.location.href='@Url.Action("Index", "Home")'">Back</button>
    <button type="button" class="btn btn-primary" onclick="window.location.href='@Url.Action("Create", "Reports", new { @id = Model.ProjectId })'">New Report</button>
</p>

<!-- This is the hidden input i'd like to pass as an additional query option-->
@Html.HiddenFor(x => x.ProjectId)

<div id="reportList">
    @Html.MVCGrid("ReportsGrid")
</div>
johnpreed commented 9 years ago

The additional option i need is passed as a query string parameter. so i tried setting the additional query options on document ready.

$(function () {
    initAdditionalOptions();
});

function initAdditionalOptions() {
    MVCGrid.setAdditionalQueryOptions("ReportsGrid", { projectId: $('#ProjectId').val() });
}

That technically works, but the id is in the url twice now: /Reports/Index/21?projectid=21

i can live with this, but is there a better approach here?

joeharrison714 commented 9 years ago

John, I believe I have a solution for you, but can you do me a huge favor and post to stackoverflow and then I will create the tag? This will help me out so others can ask questions on there. Just post the link to the question after. Thanks, Joe

johnpreed commented 9 years ago

http://stackoverflow.com/questions/30044391/how-do-i-send-an-additional-parameter-to-my-mvcgrid-net-retrievedatamethod

joeharrison714 commented 9 years ago

Thank you, I've responded on there