This is a migrated thread and some comments may be shown as answers.

parameterMap

5 Answers 1288 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Curt Rabon
Top achievements
Rank 1
Veteran
Curt Rabon asked on 15 Jun 2015, 02:58 PM

I'm using batch-mode and server-side operations. it looks like you do some special things in the parameterMap function (behind the scenes) when the operation == "read" and filtering is applied.  For example, when a filter is applied to a column, it seems you put the filtering parameters in a special format before sending to the server. Even though I'm using the MVC wrappers, I can still wire-up the parameterMap feature using JavaScript. I did this for ONLY the "destroy" operation (I want to send just the IDs and not the models), but then the "read" operation no longer works when filtering is applied, because my use of parameterMap overwrites what you are doing for "read".

Can I still use the parameterMap feature for only "destroy", and not interfere with what you do with "read" ?  My desire is to send just the IDs and not the models when batch-saving deletes.

5 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 Jun 2015, 11:19 AM

Hello Curt,

 

Could you please share the implementation of the parameterMap you are using. This will allow us to provide you with more to-the-point suggestion. Generally speaking if have override the parameterMap you will need to call the base parameterMap when special transport is used. In such cased it will serialize the request parameters in the appropriate format for the special transport. 

 

However, in order to achieve the described functionality using the ASP.NET MVC wrappers, you could use the Data function of the Destroy Action. There you could override the data send to the server. For example:

.DataSource(dataSource => dataSource       
     .Ajax()    
     .Destroy(destroy => destroy.Action("Editing_Destroy", "Grid").Data("destroyData"))
 )
 
 <script type="text/javascript">
 
 function destroyData(data) {
     var models = data.models;
 
     for (var idx = 0; idx < models.length; idx++) {
         models[idx] = { ProductID: models[idx].ProductID };
     }
 }
 
 </script>

 

 

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 19 Jun 2015, 04:24 PM

Thank you for the detailed response. However, I used your exact same code and yes, the function is called where you can overwrite the models making them have ONLY the model ID property, BUT when the data is received in the controller action, ALL of the model properties are still present for each model sent. I did try using .Data() for sending "extra" parameters which does work, but it seems your wrappers send a different copy of the models than those modified by .Data().

My setup:

 @(Html.Kendo().Grid<Test_KendoMVC.Models.pn_ContractFees>()
    .Name("pn_ContractFeesGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.FeeTitle).Title("Fee Title");
        columns.Bound(c => c.BaseCharge).Title("Base Charge");
        columns.Bound(c => c.MinHours).Title("Min Hours");
    })
    .Scrollable(s => s.Enabled(true))
    .Sortable()
    .Filterable()
    .Pageable(p => p.PageSizes(new[] { 15, 30, 50 }))
    .ToolBar(tb => { tb.Create(); tb.Save(); })
    .Editable(e =>
    {
        e.DisplayDeleteConfirmation(false);
        e.Mode(GridEditMode.InCell);
    })
    .DataSource(ds => ds
        .Ajax()
        .Batch(true)
        .PageSize(30)
        .Model(model =>
        {
            model.Id(m => m.ContractFeeID);
        })
        .Create(a => a.Action("pn_ContractFeesGrid_Save", "ContractFees"))
        .Read(a => a.Action("pn_ContractFeesGrid_Read", "ContractFees"))
        .Update(a => a.Action("pn_ContractFeesGrid_Save", "ContractFees"))
        .Destroy(a => a.Action("pn_ContractFeesGrid_Delete", "ContractFees"))
        .Events(e => e
            .RequestStart("function () { gridLib.utility.clearMessages(pn_ContractFeesGrid.grid); }")
            .Error("function (e) { gridLib.utility.handleError(e, pn_ContractFeesGrid.grid); }")
        )
    )
)

function destroyData(data) {
        var models = data.models;

        for (var idx = 0; idx < models.length; idx++) {
            models[idx] = { ContractFeeID: models[idx].ContractFeeID };
        }
    }

[HttpPost]
        public ActionResult pn_ContractFeesGrid_Delete(pn_ContractFees[] models)

 

...when the pn_ContractFeesGrid_Delete action is called, the models parameter will have an array of models that were deleted in the grid, but those models will have ALL properties.  I only need the main ID property for deleting.

0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 19 Jun 2015, 05:58 PM
I'm sorry, it was a mistake on my part.  It works good, thanks again. But please give me a small example of how to override the parameterMap (and call the base), because I might need that for something else.
0
Rosen
Telerik team
answered on 22 Jun 2015, 11:11 AM

Hello Curt Rabon,

You can call the default aspnetmvc-ajax parameterMap implementation in your own paramterMap similar to the following:

var result = kendo.data.transports["aspnetmvc-ajax"].prototype.options.parameterMap.call(this, options, type);

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 24 Jun 2015, 02:36 PM
Thank you.  I don't see this documented, so this will come in handy.
Tags
Grid
Asked by
Curt Rabon
Top achievements
Rank 1
Veteran
Answers by
Rosen
Telerik team
Curt Rabon
Top achievements
Rank 1
Veteran
Share this question
or