- Home
- Forum
- ASP.NET Core - EJ 2
- ejs2 grid Custom Add button
ejs2 grid Custom Add button
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
- Explain your requirement in detail?
- Why you want to use CustomAdd button in the Grid
- Are you want to render the specific edit form for this custom Add button?
- Which type of Editing you have used (Inline/ Dialog/ Dialog Template)?
- Share the full Grid code files.
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
- Explain your exact requirement in detail.
- Which type of data-binding you have used? (local data/ remote data).
- Share the complete Grid code files.
Hi Rajapandiyan Settu,
- For data-binding, we are using remote data.
- Adding of records is done using Add button from toolbar.
- We want to save the records (added and updated) in the grid when we submit the form using Save button
- Previously you had mentioned that we can bulk save (added, changed and deleted data in the single request) to data source by click on the toolbar’s Update button or by externally calling the batchSave method.
- To enable Batch edit, set the mode property of e-grid-editSettings tag helper as Batch so as per that we changed mode to 'Batch' in e-grid-editSettings.
- Can you please share example of bulk save (added, changed and deleted data in the single request) grid data using batchSave method example?
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(); } } |
- 8 Replies
- 3 Participants
-
PR Pradnya
- Sep 20, 2021 11:38 AM UTC
- Oct 4, 2021 03:34 PM UTC