Please see my two questions below.
I'm using Kendo UI with MVC and Razor.
I have a page with header fields, and a grid.
The goal: When page is saved to database, one row is inserted for header data, and multiple rows are inserted into another table for each grid row (each row has foreign key to header row). Obviously, if I add a new header, the grid will be empty, and when I add rows to the grid, I don't have a foreign key yet, because the header data hasn't been saved yet.
What seems to be the best approach: The grid data will to be maintained client-side. In the initial page load, the grid will get data from the server (if there is data); then adding and deleting rows will be done on the client without any communication with the server. When user clicks "save" to save header and grid data, the view should post post the all the data, including the grid data, to a controller on the server.
Question 1: Can someone please provide me with some direction on how to do this, perhaps point me to some online examples?
I've started looking into how to do this, and ran into the following issue:
1) I have the grid defined in cshtml view:
<div class="row">
@(Html.Kendo().Grid<CapEdit2.Models.Matrix>()
.Editable(e => e.Mode(GridEditMode.InLine))
.Name("NewGrid")
.DataSource(d => d
.Ajax()
.ServerOperation(false)
.Model(mod => mod.Id(m => m.Id))
.Read(r => r
.Action("MatrixRead", "Report")
.Data("matrixReadData")
)
)
.Columns(c =>
{
c.Bound(m => m.Id);
c.Bound(m => m.IncludeRecordDate).Title("Include Record Date");
c.Bound(m => m.IncludeExDate).Title("Include Ex Date");
c.Bound(m => m.IncludeTransDate).Title("Include Trans Date");
c.Bound(m => m.Ddf).Title("DDF");
c.Bound(m => m.IssueDescription).Title("Issue Description");
c.Bound(m => m.Cusip).Title("Cusip");
c.Bound(m => m.Amount).Title("Amount");
c.Bound(m => m.UsMarketValue).Title("Market Value");
c.Bound(m => m.CchBasisFactor).Title("CCH Basis Factor");
c.Bound(m => m.LocalMarketValue).Title("Local Market Value");
c.Bound(m => m.FractionalRate).Title("Fractional Rate");
}
)
)
2. I have an "Add row" button, that calls this code:
var grid = $('#MyGrid').data('kendoGrid');
grid.addRow();
3. The issue: First time I click the button, a row is added. Second, and all subsequent times I click the button, a new row replaces the existing row, and the grid apparently has one row, and never has more than one row, no matter how many times I click "add row".
Question 2: Can someone tell me why I'm seeing this issue?
Thank you for your help!
Mike
I'm using Kendo UI with MVC and Razor.
I have a page with header fields, and a grid.
The goal: When page is saved to database, one row is inserted for header data, and multiple rows are inserted into another table for each grid row (each row has foreign key to header row). Obviously, if I add a new header, the grid will be empty, and when I add rows to the grid, I don't have a foreign key yet, because the header data hasn't been saved yet.
What seems to be the best approach: The grid data will to be maintained client-side. In the initial page load, the grid will get data from the server (if there is data); then adding and deleting rows will be done on the client without any communication with the server. When user clicks "save" to save header and grid data, the view should post post the all the data, including the grid data, to a controller on the server.
Question 1: Can someone please provide me with some direction on how to do this, perhaps point me to some online examples?
I've started looking into how to do this, and ran into the following issue:
1) I have the grid defined in cshtml view:
<div class="row">
@(Html.Kendo().Grid<CapEdit2.Models.Matrix>()
.Editable(e => e.Mode(GridEditMode.InLine))
.Name("NewGrid")
.DataSource(d => d
.Ajax()
.ServerOperation(false)
.Model(mod => mod.Id(m => m.Id))
.Read(r => r
.Action("MatrixRead", "Report")
.Data("matrixReadData")
)
)
.Columns(c =>
{
c.Bound(m => m.Id);
c.Bound(m => m.IncludeRecordDate).Title("Include Record Date");
c.Bound(m => m.IncludeExDate).Title("Include Ex Date");
c.Bound(m => m.IncludeTransDate).Title("Include Trans Date");
c.Bound(m => m.Ddf).Title("DDF");
c.Bound(m => m.IssueDescription).Title("Issue Description");
c.Bound(m => m.Cusip).Title("Cusip");
c.Bound(m => m.Amount).Title("Amount");
c.Bound(m => m.UsMarketValue).Title("Market Value");
c.Bound(m => m.CchBasisFactor).Title("CCH Basis Factor");
c.Bound(m => m.LocalMarketValue).Title("Local Market Value");
c.Bound(m => m.FractionalRate).Title("Fractional Rate");
}
)
)
2. I have an "Add row" button, that calls this code:
var grid = $('#MyGrid').data('kendoGrid');
grid.addRow();
3. The issue: First time I click the button, a row is added. Second, and all subsequent times I click the button, a new row replaces the existing row, and the grid apparently has one row, and never has more than one row, no matter how many times I click "add row".
Question 2: Can someone tell me why I'm seeing this issue?
Thank you for your help!
Mike