parameterMap

6 posts, 0 answers
  1. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 15 Jun 2015 Link to this post

    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.

  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 17 Jun 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 19 Jun 2015 in reply to Rosen Link to this post

    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.

  5. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 19 Jun 2015 in reply to Rosen Link to this post

    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.
  6. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 22 Jun 2015 Link to this post

    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
  7. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 24 Jun 2015 in reply to Rosen Link to this post

    Thank you.  I don't see this documented, so this will come in handy.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready