- Home
- Forum
- ASP.NET MVC
- Add new record to the end of grid
Add new record to the end of grid
Hello
I have a grid and the new added records should be the last item in the grid. I my case a grid is short (less than 10 records) and not sorted.
When I add a new records, they always become a first row.
How can I add a new record to the end of the grid?
Thanks, Tom
I have a grid and the new added records should be the last item in the grid. I my case a grid is short (less than 10 records) and not sorted.
When I add a new records, they always become a first row.
How can I add a new record to the end of the grid?
Thanks, Tom
SIGN IN To post a reply.
3 Replies
VN
Vignesh Natarajan
Syncfusion Team
February 13, 2019 05:25 AM UTC
Hi Tomislav,
Thanks for using Syncfusion products.
Query: “How can I add a new record to the end of the grid?”
From your query, we understand that you need to insert the record at last position of ejGrid. We have achieved your requirement using ActionComplete event and RowPosition property of ejGrid. By default, clicking on add icon will insert empty record (edit form) in top position. You can change the position new row by using Property RowPosition of EditSettings.
Refer the below code example
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.dataSource2)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().RowPosition(RowPosition.Bottom); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
……………………………………………………………………………………………………………………………………
}).ClientSideEvents(e => e.ActionComplete("onActionComplete"))
)
<script type="text/javascript">
function onActionComplete(args) {
if (args.requestType == "save") {
this.model.dataSource.shift();// Remove the newly added record from first position
this.model.dataSource.push(args.data)// Push the newly added record in data source
this.refreshContent();
}
}
</script> |
For your convenience we have prepared a sample which can be downloaded from below link
Note: Provided solution will work only for local data. if you are using remote please get back to us with details regarding your dataSource.
Refer our API documentation for your reference
Regards,
Vignesh Natarajan
TT
Tomislav Tustonic
February 13, 2019 06:44 PM UTC
This is fine, thank you.
Tom
Tom
VN
Vignesh Natarajan
Syncfusion Team
February 14, 2019 03:53 AM UTC
Hi Tomislav,
Thanks for the update.
We are glad to hear that your query has been resolved by our solution.
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
TT Tomislav Tustonic
- Feb 12, 2019 03:16 PM UTC
- Feb 14, 2019 03:53 AM UTC