@Grid
<ej-Button ID="refresh" Type="Button" Text="selectedReocds" click="Click" />
<ej-grid id="FlatGrid" allow-sorting="true" allow-paging="true" allow-reordering="true" selectiontype="Multiple">
. . .
<e-datamanager url="/Home/DataSource" update-url="/Home/Edit" insert-url="/Home/Create" remove-url="/Home/Delete" adaptor="UrlAdaptor" />
<e-columns>
. . .
</e-columns>
</ej-grid>
<script type="text/javascript">
function Click() {
var obj = $(".e-grid").ejGrid("instance");
var data = obj.getSelectedRecords();
$.ajax({
type: "POST",
//send the selected records to server side while button click
url: "Home/SelectedRecords",
datatype: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Grid1Data: JSON.stringify(data) }),
success: function (result) {
}
});
}
</script> |
Hi Chris,Thanks for contacting Syncfusion Support.We have checked your query and you can get the selected records on server end by using the following KB:-
For checkbox selection:-https://www.syncfusion.com/kb/9117/how-to-get-selected-records-from-all-pages-in-multicheckbox-feature-with-remote-dataStill you faced the issue, please share us the following details.
- Complete Grid code example(server and client end).
- Screenshot if you have faced any issue.
- Do you need selected records on external button click or while on selecting the records.
- Have you used normal selection/checkbox selection.
Regards,Farveen sulthana T
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
@Html.AntiForgeryToken()
<div>First Grid</div>
<ejs-grid id="Grid1" toolbarClick="toolbarClick" allowPaging="true" load="onLoad1" toolbar="@( new List<object>() {"Add","Update","Cancel", "Selected"})">
<e-data-manager url="/Index?handler=DataSource" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-pageSettings pageCount="5" pageSize="5"></e-grid-pageSettings>
<e-grid-columns>
<e-grid-column type="checkbox" width="50"></e-grid-column>
. . .
</e-grid-columns>
</ejs-grid>
<script>
function onLoad1() {
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
}
function toolbarClick(e) {
console.log(e);
if (e.item.text == "Selected") {
var grid = document.getElementById("Grid1").ej2_instances[0];
var data = grid.getSelectedRecords();
$.ajax({
type: "POST",
url: "/Index?handler=Selected",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
contentType: "application/json",
dataType: "json",
data: JSON.stringify({ dm: data }), //Pass the selected row index value to server side
success: function (response) {
console.log(response);
},
failure: function (response) {
alert(response);
}
});
}}
</script> |
public JsonResult OnPostSelected([FromBody]Selecteddata<OrdersDetails> dm)
{
return new JsonResult(new { result =dm }) ;
} |
|