|
@{
List<object> commands = new List<object>();
commands.Add(new { type = "userstatus", buttonOption = new { content = "Details", cssClass = "e-flat e-details" } }); // custom
}
<div class="control-section">
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" commandClick="commandClick" allowPaging="true">
. . .s
<e-grid-column headerText="Manage Records" width="150" commands="commands"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
function commandClick(args) {
// here we are making an ajax call to server
var ajax = new ej.base.Ajax({
url: "/Home/CommandColumnHanlde",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: args.rowData })
});
ajax.send();
ajax.onSuccess = function (data) {
// on the success event we are showing the data returned from server
alert(data);
};
}
</script> |
|
[Home controller]
namespace TestSample.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.DataSource = OrdersDetails.GetAllRecords().ToList();
return View();
}
public OrdersDetails CommandColumnHanlde([FromBody] CRUDModel<OrdersDetails> value)
{
return value.Value;
}
}
}
|
Hello Dear, What about if i want to make 2 custom button with two diff events ?
|
@{
List<object> commands = new List<object>();
commands.Add(new { type = "userstatus_1", buttonOption = new { content = "Details-1", cssClass = "e-flat e-details" } });
commands.Add(new { type = "userstatus_2", buttonOption = new { content = "Details-2", cssClass = "e-flat e-details" } }); // custom
}
<div class="control-section">
<div class="col-lg-6">
<ejs-grid id="Grid" dataSource="ViewBag.DataSource1" commandClick="commandClick" allowSelection="true" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "Search" })">
<e-grid-editSettings allowAdding="false" allowDeleting="false" allowEditing="true" mode="Dialog"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="OrderID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="Employee ID" width="150" allowEditing="true"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="Employee ID" width="150" allowEditing="false"></e-grid-column>
<e-grid-column field="ShipState" headerText="Ship City" width="150" allowEditing="true"></e-grid-column>
<e-grid-column headerText="Manage Records" width="150" commands="commands"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
</div>
<style>
</style>
<script>
function commandClick(args) {
if(args.commandColumn.type == "userstatus_1") {
// here we are making an ajax call to server
var ajax = new ej.base.Ajax({
url: "/Home/CommandColumnHanlde",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: args.rowData })
});
ajax.send();
ajax.onSuccess = function (data) {
// on the success event we are showing the data returned from server
alert(data);
};
}
else if(args.commandColumn.type == "userstatus_2") {
// perform actions for second button here.
}
}
</script>
|