loadComplete and UserData

Apr 23, 2013 at 1:29 AM
Edited Apr 23, 2013 at 1:29 AM
Hey Tomasz.
I'm back with a question
I have included in the response sent by the server a UserData

In the controller
var response = new JqGridResponse {
....
UserData = new { 
             Subutotal = query.Sum(x => x.Monto)
            }
};
In the view
var grid = new JqGridHelper<...>(
                              "comisiones",
                               dataType: JqGridDataTypes.Json,
                               methodType: JqGridMethodTypes.Post,
                               .....
                               loadComplete: "actualizar()"
);
In the Javascript Section
$(document).ready(function() {
         @grid.GetJavaScript()
});

function actualizar() {
      if(JQuery("#comisiones").getGridParam('datatype') === "json"){
           var userdata= JQuery("#comisiones").getGridParam('userData´);
           $("#Subtotal").val(userdata.Subutotal);
      }
}
The main code is here and is courtesy of Oleg

But this is not working when generating the grid through your library.
What would be the right way to get Subutotal
Coordinator
Apr 23, 2013 at 7:55 AM
Hi,

For start please change your JavaScript like this:
function actualizar() {
    //Or jQuery('#comisiones'), notice that "j" is not capitalized, this is important as JavaScript is case sensitive
    var grid = $('#comisiones');
    if (grid.jqGrid('getGridParam', 'datatype') === 'json') {
        var userdata= grid.jqGrid('getGridParam', 'userData');
        $("#Subtotal").val(userdata.Subutotal);
    }
}
If that doesn't help I will make some further testing, also I'm not able to verify that your selectot for Subtotal element is correct, and it is a type of element on which you can use jQuery.val(); (you can post the relevant HTML in order for me to verify that).
Apr 24, 2013 at 12:46 AM
Edited Apr 24, 2013 at 12:53 AM
This is the otuput of ActionResult List:
Image

I changed the code as you suggest it but the problem is that the parameter datatype is "undefined"

This is the full code of ActionResult ComisionesBruto. I must send a parameter called "Bruto" to calculate commissions
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ComisionesBruto(string type, string bruto, int cabezas, JqGridRequest request)
        {
            var query = GetComisionesBruto(type, Convert.ToDecimal(bruto, CultureInfo.InvariantCulture) ,cabezas);
            var totalRecords = query.Count();
            var response = new JqGridResponse
            {
                //Total pages count
                TotalPagesCount = (int)Math.Ceiling(totalRecords / (float)request.RecordsCount),
                ////Page number
                PageIndex = request.PageIndex,
                ////Total records count
                TotalRecordsCount = totalRecords,
                //// SubTotal is decimal
                UserData= new {Subtotal = query.Sum(x=> x.Monto)}
            };
            response.Records.AddRange(
                from r in query.Skip(request.PageIndex * request.RecordsCount).Take(request.RecordsCount)
                select new JqGridRecord<ComisionBruto>((Convert.ToString(r.ComisionImpuestoId)),
                                                                   new ComisionBruto
                                                                   {
                                                                       ComisionImpuestoId = r.ComisionImpuestoId, NombreComision = r.NombreComision,
                                                                       Formula = r.Formula, Monto = r.Monto,
                                                                       Valor= r.Valor, Cantidad= r.Cantidad
                                                                   }));
            return new JqGridJsonResult { Data = response };
        }
This is the full code of the view.
@using System.Globalization
@using Lib.Web.Mvc.JQuery.JqGrid;
@model Ferias.WebUI.Models.FacturaHeaderModel
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    var grid = new JqGridHelper<Ferias.WebUI.Models.ComisionBruto>(
        "comisiones",
        dataType: JqGridDataTypes.Json,
        methodType: JqGridMethodTypes.Post,
        pager: true,
        width: 350,
        rowsNumber: 5,
        loadComplete: "actualizar()",
        sortingName: "ComisionImpuestoId",
        parametersNames: new JqGridParametersNames {Id = "ComisionImpuestoId"},
        sortingOrder: JqGridSortingOrders.Asc,
        url: Url.Action("ComisionesBruto", "Comisiones", new {type = "C", bruto = Model.Bruto.ToString(CultureInfo.InvariantCulture), cabezas = Model.Cabezas}),
        viewRecords: true
        ).Navigator(new JqGridNavigatorOptions {Search = false, Add = false, Edit = false, Delete = false}); 
}
@section JavaScript {
<script type="text/javascript">
    $(document).ready(function() {
        $.datepicker.setDefaults($.datepicker.regional['es']);
        $("#Fecha").datepicker({ changeMonth: true, autoSize: true });
        @grid.GetJavaScript()
    });
    function actualizar() {
        var grid = $('#comisiones');
        if (grid.jqGrid('getGridParam', 'datatype') === 'json') {
            var userdata = grid.jqGrid('getGridParam','userData');
            var s = parseFloat(@Model.Bruto) + parseFloat(userdata.Subtotal);
            $('#SubTotal').val(s);
        }
    }
</script>
}    
    <fieldset>
....
        <div class="editor-label">
            @Html.LabelFor(m => m.Bruto)
            <div class="editor-field">
                @Html.EditorFor(m => m.Bruto, "Currency")
            </div>
        </div>
        <div class="editor-label">
            @Html.LabelFor(m => m.SubTotal)
            <div class="editor-field">
                @Html.EditorFor(m => m.SubTotal, "Currency")
            </div>
        </div>
        <br/>
    @grid.GetHtml()
Apr 24, 2013 at 1:15 AM
II have include a message in function Actulizar
    function actualizar() {
        var grid = $('#comisiones');
        alert('datatype is ' +grid.jqGrid('getGridParam', 'datatype'));
        if (grid.jqGrid('getGridParam', 'datatype') === 'json') {
            var userdata = grid.jqGrid('getGridParam','userData');
            var s = parseFloat(@Model.Bruto) + parseFloat(userdata.Subtotal);
            $('#SubTotal').val(s);
        }
    }
Image
Coordinator
Apr 24, 2013 at 9:54 AM
I will try to recreate the issue later today and see what is causing the problem (but in case when it is a problem with datatype param it might be seeming in jqGrid itself as helper doesn't do any specific there).
Coordinator
Apr 24, 2013 at 9:39 PM
I finally see what is causing the issue. You are passing the function name with () which is telling jqGrid to run function while initializing, not to attach it as event handler (the potential result of that function might be attached instead). The code should look like this:
var grid = new JqGridHelper<Ferias.WebUI.Models.ComisionBruto>(
    ...
    loadComplete: "actualizar",
    ...
).Navigator(new JqGridNavigatorOptions {Search = false, Add = false, Edit = false, Delete = false}); 
Apr 25, 2013 at 10:36 AM

you are the best

El 24/04/2013 18:39, "TPeczek" <[email removed]> escribió:

From: TPeczek

I finally see what is causing the issue. You are passing the function name with () which is telling jqGrid to run function while initializing, not to attach it as event handler (the potential result of that function might be attached instead). The code should look like this:
var grid = new JqGridHelper<Ferias.WebUI.Models.ComisionBruto>(
    ...
    loadComplete: "actualizar",
    ...
).Navigator(new JqGridNavigatorOptions {Search = false, Add = false, Edit = false, Delete = false}); 

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com