This question is locked. New answers and comments are not allowed.
I am kind of fed up with trying to figure Ajax Grid parameters. I have created several grids and the parameters just kind of seem to be willy-nilly, I try one thing, it doesn't work for one, then works for another.
My understanding is that you really don't have to put the parameters in the .DataBinding if those parameters exist in the .DataKeys collection? This seems to be arbitrary when it works and when it doesn't.
Can someone give me a short overview about Ajax grid binding and passing parameters to a controller so I can select data to populate it with? Why is it I need to define the parameters and other times it works like magic?
Lately, every little think seems to be a battle with the Telerik MVC controls, even stuff I have done 5-6 times before.
In this case:
LineItemID is the primary key and JobID is a foreign key. I really want to pass the JobID to the select binding. I want to grab all line items with a specific JobID.
View:
Controller:
Thanks in advance for any insight.
Steve
My understanding is that you really don't have to put the parameters in the .DataBinding if those parameters exist in the .DataKeys collection? This seems to be arbitrary when it works and when it doesn't.
Can someone give me a short overview about Ajax grid binding and passing parameters to a controller so I can select data to populate it with? Why is it I need to define the parameters and other times it works like magic?
Lately, every little think seems to be a battle with the Telerik MVC controls, even stuff I have done 5-6 times before.
In this case:
LineItemID is the primary key and JobID is a foreign key. I really want to pass the JobID to the select binding. I want to grab all line items with a specific JobID.
View:
@{ Grid<
viaLanguage.Jams.Data.tblJobManagementLineItem
> grid = Html.Telerik().Grid<
viaLanguage.Jams.Data.tblJobManagementLineItem
>()
.Name("InvoiceLineItemsGrid")
.DataKeys(keys =>
{
keys.Add(i => i.LineItemID).RouteKey("lineItemID");
keys.Add(i => i.JobID).RouteKey("jobID");
})
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("_SelectInvoiceLineItems", "Job", new { jobID = "<#= JobID #>" })
.Insert("_InsertJobInvoice", "Job")
.Update("_UpdateJobInvoice", "Job")
.Delete("_DeleteJobInvoice", "Job"))
.ToolBar(commands => commands.Insert().HtmlAttributes(new { style = "margin-left:0" }))
.Columns(columns =>
{
columns.Bound(l => l.LineItemDescr).Width(180).HeaderTemplate("Task");
columns.Bound(l => l.LanguagePairID).Width(100).HeaderTemplate("Language Pair").ClientTemplate("<#= LanguagePair #>");
columns.Bound(l => l.SourceWordCount).Width(100).HeaderTemplate("Source Words");
columns.Bound(l => l.QtyToInvoice).Width(100).HeaderTemplate("Quantity to Invoice");
columns.Bound(l => l.Rate).Width(50).Format("${0:0.000}").HeaderHtmlAttributes(new { style = "text-align: center;" }).HtmlAttributes(new { style = "text-align: center;" });
columns.Bound(l => l.SubTotal).Width(100).Format("{0:c}");
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image);
commands.Delete().ButtonType(GridButtonType.Image);
}).Width(80).HtmlAttributes(new { style = "white-space: nowrap;" });
})
.Resizable(resizing => resizing.Columns(true))
.Sortable()
.Selectable()
.Pageable(paging => paging.PageSize(10))
.Scrollable(c => c.Height("233px"))
.Filterable();
StringWriter sw = new StringWriter();
grid.Render();
grid.WriteInitializationScript(sw);
}
Controller:
[GridAction]
public
ActionResult _SelectInvoiceLineItems(
int
jobID)
{
logLogic.logger.Debug(logLogic.GetMethodName() +
": User '"
+ User.Identity.Name);
return
View(
new
GridModel(jobLogic.GetInvoiceLineItems(jobID, User.Identity.Name)));
}
Thanks in advance for any insight.
Steve