Click here to Skip to main content
15,885,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project,i dynamically adding new rows to the kendo grid.I entered datas to that row.But on appending new row to the grid the entered datas gets cleared.I am trying to add batch creating of records. here i used kendo widgets in all columns.My code is
HTML
@(Html.Kendo().Grid<POC_Grid.TblProductDetails>()
    .Name("Grid")
    .Columns(column =>
    {
        //column.Template(m => m.Id);
        column.Template(m => m.Item).HtmlAttributes(new { @class = "templateCell" }).ClientTemplate(Html.Kendo().AutoComplete()
                    .Name("Item#=uid#")
                    .DataTextField("Item")
                    .Filter("startswith")
                    .MinLength(1)
                    .HtmlAttributes(new { style = "width:250px", @class = "templateCell" })
                    .DataSource(source =>
                    {
                        source.Read(read =>
                        {
                            read.Action("getFilteredData", "Grid")
                            .Data("filterDataByText");
                        })
                        .ServerFiltering(true);
                    })

                    .ToClientTemplate().ToHtmlString());

        column.Template(m => m.Units).HtmlAttributes(new { @class = "templateCell" }).ClientTemplate(Html.Kendo().NumericTextBox<decimal>()
                    .Name("Units#=uid#")
                    .Format("c")
                    .Min(0)
                    .Max(100)
                    .HtmlAttributes(new { @class = "templateCell" })
                    .ToClientTemplate().ToHtmlString());
        column.Template(m => m.SingleUnitPrice).HtmlAttributes(new { @class = "templateCell" }).ClientTemplate(Html.Kendo().NumericTextBox<decimal>()
                    .Name("SingleUnitPrice#=uid#")
                    .Format("c")
                    .Min(0)
                    .Max(100)
                    .HtmlAttributes(new { @class = "templateCell" })
                    .ToClientTemplate().ToHtmlString());
        column.Template(m => m.Total).HtmlAttributes(new { @class = "templateCell" }).ClientTemplate(Html.Kendo().NumericTextBox<decimal>()
                    .Name("Total#=uid#")
                    .Min(0)
                    .Max(100)
                    //.HtmlAttributes(new { @readonly = "readonly" })
                    .HtmlAttributes(new { @class = "templateCell",@title="total" })
                    .ToClientTemplate().ToHtmlString());
    })
                .Events(ev => ev.DataBound("templateScript")
            )

        .ToolBar(toolbar =>
        {
            toolbar.Create().Text("+");
            toolbar.Save();
        })
        .Editable(m => m.Mode(GridEditMode.InCell))
        .Pageable(p=>p.Refresh(false))
        .Sortable()
        .Scrollable()
        .Selectable()
        .HtmlAttributes(new { style = "height:430px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .Model(model =>
            {
                model.Id(p => p.Id);
            })
            .PageSize(20)
            //.Model(m => { m.Id(c => c.Id); })
                .Create(create => create.Action("Grid_Create", "Grid"))
                .Update(update => update.Action("Grid_Update", "Grid"))
                //.Read(read => read.Action("Grid_Read", "Grid"))
)

My kendo bound event is:
JavaScript
<script>
function templateScript(e) {
    $(".templateCell").each(function () {
        eval($(this).children("script").html());
    });
}
</script> 


For appending new row i used
JavaScript
var grid = $("#Grid").data("kendoGrid");
grid.addRow()


After appending new row the existing row datas gets cleared.I think these occurs due to datasource is cleared.Plz tell some suggestion to overcome these problem.On appending new rows the existing row datas cannot get cleared.And if i tried to add batch save to database.It saves null values only.I tried these for so many hours.I couldn't get proper solutions.
</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900