javascript - Devextreme dxDataGrid: Pass selected RowData to function when clicking on a button on that Row -
i using dxdatagrid
ui widget of devextreme product.
i want make 1 of column act button. therefore, have done following listing far:
one of fields
{ datafield: 'letternumber', caption: 'letter number', celltemplate: showletterimagetemplate }
its celltemplate show button
function showletterimagetemplate (cellelement, cellinfo) { cellelement.html(' <button class="btn btn-info btn-sm btn-block" ng-click="show('+cellinfo+')">' + cellinfo.displayvalue + ' </button> '); $compile(cellelement)($scope); };
the function called clicking on buttons in field
$scope.show = function (cellinfo) { devexpress.ui.notify("test" + cellinfo.data, "error", 2000); }
the problem want pass current clicked row data show()
function can understand row has been clicked on. however, when click on button gives me following error:
ng-click=show([object object])
just note, using agular ui framework.
try use following code define celltemplate
:
$scope.onclick = function(cellinfo) { // cellinfo object }; $scope.datagridoptions = { datasource: [ { name: "alex", age: 23 }, { name: "bob", age: 25 } ], columns: [ "name", { datafield: "age", celltemplate: function(cellelement, cellinfo) { var $button = $("<button>") .text("click me") .on("click", $.proxy($scope.onclick, this, cellinfo)); cellelement.append($button); } } ] };
next, add markup view:
<div dx-data-grid="datagridoptions"></div>
hope helps!
Comments
Post a Comment