How to SubGrid Extra Param

Jan 23, 2013 at 2:14 PM

Hello Tomas, Suppose the following code

 

        var grid = new JqGridHelper<Estudio.WebUI.Models.ClienteGridViewModel>("Clientes",
        dataType: JqGridDataTypes.Json,
        methodType: JqGridMethodTypes.Post,
        pager: true,
        width: 1000,
        rowsList: new List<int> { 10, 15, 20, 25, 30 },
        sortingName: "ClienteId",
        parametersNames: new JqGridParametersNames { Id = "ClienteId" },
        sortingOrder: JqGridSortingOrders.Asc,
        url: Url.Action("List"),
        subgridEnabled:true,
        subgridHelper: new JqGridHelper<Estudio.WebUI.Models.HonorariosModel>("honorarioDetails",
            dataType: JqGridDataTypes.Json,
            methodType: JqGridMethodTypes.Post,
            width: 600,          
            pager: true,
            rowsList: new List<int> { 10, 15, 20, 25, 30 },
            parametersNames: new JqGridParametersNames { Id = "HonorarioId" },
            sortingName: "HonorarioId",
            sortingOrder: JqGridSortingOrders.Asc,
            url: Url.Action("DetailSubgrid", "Honorarios"),
            viewRecords: true
        ).Navigator(new JqGridNavigatorOptions() { Search = false },
            addActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update","Honorarios"), CloseAfterEdit = true, ClearAfterAdd = true},
            editActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update", "Honorarios"), CloseAfterEdit = true, ClearAfterAdd = true },
            deleteActionOptions: new JqGridNavigatorDeleteActionOptions { Url = Url.Action("Delete", "Honorarios") }),
        viewRecords: true
    ).Navigator(new JqGridNavigatorOptions { Search = false },
    addActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update"), CloseAfterEdit = true, ClearAfterAdd = true, Width = 500},
    editActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update"), CloseAfterEdit = true, ClearAfterAdd = true, Width = 500 },
    deleteActionOptions: new JqGridNavigatorDeleteActionOptions { Url = Url.Action("Delete") });


The question is: how to send the "ClienteId" attribute to edit or add a record on SubGrid?

This should be done with AjaxOptions? You can include an example?

Thanks

 

Coordinator
Jan 24, 2013 at 3:23 PM

Hi,

You can leverage the fact, that the subgrid initialization code is being placed in subGridRowExpanded callback, which looks like this:

subGridRowExpanded: function(subgridId, rowId) {
    ...
}

The rowId parameter is the id of parent row (in your case it is "ClienteId"). Thanks to this you can provide a simple script for ExtraDataScript property which will add this value to the requests:

var grid = new JqGridHelper<Estudio.WebUI.Models.ClienteGridViewModel>("Clientes",
	dataType: JqGridDataTypes.Json,
	methodType: JqGridMethodTypes.Post,
	pager: true,
	width: 1000,
	rowsList: new List<int> { 10, 15, 20, 25, 30 },
	sortingName: "ClienteId",
	parametersNames: new JqGridParametersNames { Id = "ClienteId" },
	sortingOrder: JqGridSortingOrders.Asc,
	url: Url.Action("List"),
	subgridEnabled:true,
	subgridHelper: new JqGridHelper<Estudio.WebUI.Models.HonorariosModel>("honorarioDetails",
		dataType: JqGridDataTypes.Json,
		methodType: JqGridMethodTypes.Post,
		width: 600,          
		pager: true,
		rowsList: new List<int> { 10, 15, 20, 25, 30 },
		parametersNames: new JqGridParametersNames { Id = "HonorarioId" },
		sortingName: "HonorarioId",
		sortingOrder: JqGridSortingOrders.Asc,
		url: Url.Action("DetailSubgrid", "Honorarios"),
		viewRecords: true
	).Navigator(new JqGridNavigatorOptions() { Search = false },
		addActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update","Honorarios"), CloseAfterEdit = true, ClearAfterAdd = true, ExtraDataScript = "{ ClienteId: rowId }" },
		editActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update", "Honorarios"), CloseAfterEdit = true, ClearAfterAdd = true, ExtraDataScript = "{ ClienteId: rowId }" },
		deleteActionOptions: new JqGridNavigatorDeleteActionOptions { Url = Url.Action("Delete", "Honorarios") }),
	viewRecords: true
).Navigator(new JqGridNavigatorOptions { Search = false },
    addActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update"), CloseAfterEdit = true, ClearAfterAdd = true, Width = 500},
    editActionOptions: new JqGridNavigatorEditActionOptions { Url = Url.Action("Update"), CloseAfterEdit = true, ClearAfterAdd = true, Width = 500 },
    deleteActionOptions: new JqGridNavigatorDeleteActionOptions { Url = Url.Action("Delete") });

This should solve your issue.

Jan 24, 2013 at 4:37 PM

Simply, you are the best!!!