You can easily add item in you kendo grid in client side.
In your button or other control:
<table style="clear: left">
<tr>
<td>
@Html.LabelFor(model => model.JV_ACCOUNT_CODE)
</td>
<td>
@Html.TextBoxFor(model => model.JV_ACCOUNT_CODE)
@Html.ValidationMessageFor(model => model.JV_ACCOUNT_CODE)
</td>
<td>
@Html.LabelFor(model => model.JV_CurrentBalance)
</td>
<td>
@Html.TextBoxFor(model => model.JV_CurrentBalance)
@Html.ValidationMessageFor(model => model.JV_CurrentBalance)
</td>
</tr>
</table>
<br />
<table>
<tr>
<td>
@Html.LabelFor(model => model.JV_NOTES)
</td>
<td>
@Html.TextBoxFor(model => model.JV_NOTES)
@Html.ValidationMessageFor(model => model.JV_NOTES)
</td>
<td>
@Html.LabelFor(model => model.JV_DATE)
</td>
<td>
@Html.EditorFor(model => model.JV_DATE)
@Html.ValidationMessageFor(model => model.JV_DATE)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.JV_AMOUNT)
</td>
<td>
@Html.TextBoxFor(model => model.JV_AMOUNT)
@Html.ValidationMessageFor(model => model.JV_AMOUNT)
</td>
<td>
@Html.DropDownList("JV_Transaction_TYPE", Model.ddlTransactionTypeType, new { @style = "width:150px" })
@Html.ValidationMessageFor(model => model.JV_Transaction_TYPE)
@Html.HiddenFor(model => model.JV_Transaction_TYPE)
</td>
<td>
<a class="btn btn-mini btn-primary" id="lnkAddToGrid" href='#' >
<i class="icon-plus"></i>Add
</a>
</td>
</tr>
</table>
<div id="CustomerPackageChannelKendoGridAdd" >
</div>
Id Change event will add item in to grid
var currentId = 0;
$("#lnkAddToGrid").click(function (e) {
e.preventDefault();
// Get the Kendo Grid
var dataSource = $("#CustomerPackageChannelKendoGridAdd").data("kendoGrid").dataSource;
// Get value from another field
var _JV_ACCOUNT_ID = $('#JV_ACCOUNT_ID').val();
var _JV_ACCOUNT_NAME = $('#JV_ACCOUNT_NAME').val();
var _JV_ACCOUNT_CODE = $('#JV_ACCOUNT_CODE').val();
var _JV_NOTES = $('#JV_NOTES').val();
var _JV_DATE = $('#JV_DATE').val();
var type = $('#JV_Transaction_TYPE').val();
// You can set condition if required for you
if (CheckExistingData(gridDataAdd, _JV_ACCOUNT_ID) == false) {
currentId += 1;
dataSource.add(
{
id: currentId,
JV_ACCOUNT_ID: _JV_ACCOUNT_ID,
JV_ACCOUNT_NAME: _JV_ACCOUNT_NAME
, JV_ACCOUNT_CODE: _JV_ACCOUNT_CODE
, JV_NOTES: _JV_NOTES
, JV_DATE: _JV_DATE
, JV_DEBIT_AMOUNT: _JV_DEBIT_AMOUNT
, JV_CREDIT_AMOUNT: _JV_CREDIT_AMOUNT
});
}
// (Optional: If you want to sum any specific grid column value & set it another textbox field)
var dataSource1 = $("#CustomerPackageChannelKendoGridAdd").data("kendoGrid").dataSource.data();
var dataSource2 = $("#CustomerPackageChannelKendoGridAdd").data("kendoGrid").dataSource.data();
var totaldebit = 0;
var v;
for (var i = 0; i < dataSource1.length; i++) {
v = parseFloat(dataSource1[i].JV_DEBIT_AMOUNT);
if (!isNaN(v)) totaldebit += v;
}
document.getElementById('JV_TOTAL_DEBIT_AMOUNT').value = totaldebit;
});
Grid Script:
<script>
$("#CustomerPackageChannelKendoGridAdd").kendoGrid({
dataSource:
{
schema:
{
model:
{
fields:
{
JV_ID: { type: "string" },
JV_ACCOUNT_ID: { type: "string" },
JV_ACCOUNT_NAME: { type: "string" },
JV_ACCOUNT_CODE: { type: "string" },
JV_NOTES: { type: "string" },
JV_DATE: { type: "string" },
JV_DEBIT_AMOUNT: { type: "string" },
JV_CREDIT_AMOUNT: { type: "string" },
JV_BANK_REMARK: { type: "string" }
}
}
},
pageSize: 20,
serverPaging: false,
serverFiltering: false,
serverSorting: false
},
height: 200,
filterable: true,
groupable: true,
sortable: true,
resizable: true,
editable: true,
selectable: true,
pageable:
{
refresh: false,
pageSizes: [20, 40, 60, 80, 100]
},
columns:
[
{ field: "JV_ID", title: "JV_ID", hidden: true, filterable: false, sortable: false },
{ field: "JV_ACCOUNT_ID", title: "JV_ACCOUNT_ID", hidden: true, filterable: false, sortable: false },
{ field: "JV_ACCOUNT_NAME", title: "Account Name", width: "20%" },
{ field: "JV_ACCOUNT_CODE", title: "Account Code", width: "20%" },
{ field: "JV_NOTES", title: "JV_NOTES", hidden: true, filterable: false, sortable: false },
{ field: "JV_DATE", title: "JV_DATE", hidden: true, filterable: false, sortable: false },
{ field: "JV_DEBIT_AMOUNT", title: "Dr", width: "20%" },
{ field: "JV_CREDIT_AMOUNT", title: "Cr", width: "20%" },
{
command:
[
{
name: "Del", imageClass: "k-icon k-i-close", click: function (e) {
e.preventDefault();
var dataItem = this.dataItem($(e.target).closest("tr"));
//if (confirm('Do you want to delete record?')) {
var dataSource = $("#CustomerPackageChannelKendoGridAdd").data("kendoGrid").dataSource;
dataSource.remove(dataItem);
dataSource.sync();
//}
}
}
], title: " ", width: "15%"
}
]
});
</script>
Comments
Post a Comment