Hi , I have a ejs-grid . Instead of using Add from toolbar , I want to add custom Add button that will add dynamic data to the grid
Hi Rajapandiyan S,
We have requirement wherein we want excel like add edit.
Toolbar grid edit option we are not using.
clicking on individual cell we are editing row and then saving entries by clicking on form Save
While editing records, the Add option from Toolbar gets disabled, Update & cancel are enabled.
But when I want to add new record, the Add button gets disabled from toolbar so cannot perform add operation
thus wanted to use Custom Add button in the grid which will add new blank where I can add dynamic details . do this multiple times and then save all entries on form Save
Hi
Rajapandiyan Settu,
Can you help me with batchSave method.
I want to save the edited records & newly added records on form save button
I have checked https://www.syncfusion.com/forums/167803/how-to-check-if-grid-has-changes-with-js-jquery
but the changed records are not getting updated in the grid
Regards,
Pradnya
Hi Rajapandiyan Settu,
We are just using Add button provided on the toolbar (Update & Cancel are not used from toolbar)
mode="Batch" in e-grid-editSettings
instance.editModule.batchSave(); //This line does not updates the grid datasource with the latest updated data
tempbatchChanges.changedRecords // This has the changes for row that has the updated data
Code snippet:-
//On form Save, we are saving the changes on the grid (added records + updated records)
document.getElementById("editPublicationForm").addEventListener("submit", e => {
var instance = document.getElementById("authorsGrid").ej2_instances[0];
if (instance.isEdit) {
instance.endEdit();
}
var tempbatchChanges = instance.getBatchChanges();
if (tempbatchChanges.addedRecords.length > 0 || tempbatchChanges.deletedRecords.length > 0 || tempbatchChanges.changedRecords.length > 0) {
// execute the batchSave method if any changes applied in Grid
instance.editModule.batchSave();
var list = instance.dataSource; //grid datasource
instance.batchChanges = tempbatchChanges; //changed records
document.getElementById("ID_AuthorList").value = JSON.stringify(list);
}
document.getElementById("ID_AuthorList").value = JSON.stringify(instance.dataSource);
});
Any help would be great.
Thanks & Regards,
Pradnya
Hi Rajapandiyan Settu,
Code:-
<ejs-grid id="authorsGrid" dataSource="Model.FullAuthorList" allowResizing="true" allowRowDragAndDrop="true" allowReordering="true" allowSelection="true" toolbar="@(new List<string>() { "Add", "Update" , "Cancel" })" actionComplete="onComplete" actionBegin="onBegin">
<e-grid-editSettings allowAdding="true" allowEditing="true" allowDeleting="true" showDeleteConfirmDialog="true" mode="Batch" allowEditOnDblClick="false" newRowPosition="Bottom"></e-grid-editSettings>
<e-grid-columns>
<e-grid-columns>
<e-grid-column field="Order" width="70" headerText="SrNo" allowResizing="false" allowEditing="false"></e-grid-column>
<e-grid-column field="FirstName" width="200" headerText="First Name" allowResizing="false"></e-grid-column>
<e-grid-column field="LastName" width="200" headerText=" Last Name" allowResizing="false"></e-grid-column>
</e-grid-columns>
</ejs-grid>
Regards,
Pradnya
|
[Index.cshtml]
<form action="/Home/FormSubmition" onsubmit='return validate()' method="post">
<button>Submit</button>
<input type="hidden" name="GridData" id="hdndata" />
</form>
<ejs-grid id="Grid" dataSource="@ViewBag.dataSource" allowPaging="true" toolbar="@(new List<string>()"Add","Delete","Update","Cancel" , "ExcelExport","PdfExport"})" allowPdfExport="true" allowExcelExport="true">
<e-grid-editSettings allowAdding="true" allowDeleting="true" showConfirmDialog="false" allowEditing="true" mode="Batch" >
</e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" validationRules="@(new { required=true})" width="150"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" format="C2" width="120"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" minWidth="20" maxWidth="500"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
function validate() { var grid = document.getElementById("Grid").ej2_instances[0]; var tempbatchChanges = grid.getBatchChanges(); if (tempbatchChanges.addedRecords.length > 0 || tempbatchChanges.deletedRecords.length > 0 || tempbatchChanges.changedRecords.length > 0 ) { grid.editModule.batchSave(); var list = grid.dataSource; grid.batchChanges = tempbatchChanges; document.getElementById("hdndata").value = JSON.stringify(list); var form = document.getElementsByTagName("form")[0]; form.submit(); } } |