telerik/ui-for-aspnet-mvc-examples

Post grid data with form through jQuery

Closed this issue · 0 comments

What about an solution like this:

$( document ).ready(
   $("form").each(function(i, form){
       $(this).find(".k-grid").each(function(_i, div){
           $(form).submit(div, kendoGridSubmitData);
       });
    });
);

function kendoGridSubmitData(e) {
    var lModel = e.data.id;
    var lKendoGrid = $(e.data).data("kendoGrid");

    // Iterate over all rows
    lKendoGrid.dataItems().forEach(function(_row, _rowIndex){
        // Iterate over all fields
        _row.forEach(function(_value, _name){
            // Add the input hidden
            $('<input>').attr({
                type: 'hidden',
                id: lModel,
                name: lModel+'['+_rowIndex+'].'+_name,
                value: _value
            }).appendTo('form');
        });
    });
}