- Home
- Forum
- ASP.NET MVC
- Add a button column to grid. Each button should call an action from the controller, passing the ID of the current element
Add a button column to grid. Each button should call an action from the controller, passing the ID of the current element
Thanks for using Syncfusion products.
We can achieve your requirement by passing the selected records to the controller while clicking the unbound button through ajax post as follows.
|
@(Html.EJ().Grid<SampleDemo1.OrdersView>("FlatGrid") col.HeaderText("Unbound Button").Commands(command => .ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties() Click = "onClick" }).Add(); .IsUnbound(true) .TextAlign(TextAlign.Center) .Width(150) .Add();
}) ) <script type="text/javascript"> function onClick(args) { var gridObj = $("#FlatGrid").data("ejGrid"); //getting corresponding record var data = gridObj.getSelectedRecords()[0].OrderID; $.ajax({ type: "POST", url: "/Grid/Query", //Sending data to the server(controller) side data: { "data": data } });
} public class GridController : Controller { public void Query(int? data) { //getting data from the client side
Console.WriteLine(data); } |
Please try the above snippet and let us know if you have any queries.
Regards,
Gowthami V.
We analyzed your requirement to handle the click event of the custom command button within the context of angularjs controller . We can achieve your requirement by binding the click event of the ejButton to the $scope variable as in the below code example.
|
<div id="Grid" ej-grid e-datasource="data" > <div e-columns> . . . . <div e-column e-headertext="Details" e-commands="command" e-isunbound=true e-textalign="center" e-width="150"></div> </div> </div>
angular.module('listCtrl', ['ejangular']) .controller('PhoneListCtrl', function ($scope) { $scope.data = obj; $scope.toolbar = ["add", "edit", "delete", "update", "cancel"]; $scope.onClick = function (args) { var gridObj = $("#Grid").data("ejGrid"); //getting corresponding record EmployeeID value var data = gridObj.getSelectedRecords()[0].EmployeeID; alert(data);
} $scope.command = [{ type: "details", buttonOptions: { text: "Details", width: "100", click: $scope.onClick, } }];;
|
We have created a sample for your convenience, which can be downloaded from the below location.
Sample Link: http://jsplayground.syncfusion.com/xg0ykdli
Regards,
Ragavee U S.
- 4 Replies
- 4 Participants
-
CA Carlo
- Jul 13, 2015 08:38 AM UTC
- Dec 9, 2015 07:30 AM UTC