Я хотел бы получить значение, введенное в текстовое поле при событии размытия в UI-Grid. Я не могу получить значение, которое вызывает событие, но не могу понять логику, как получить значение текстового поля. может кто поможет разобраться.
Это код:
$scope.gridOptions = {
headerTemplate: 'header-template.html',
showColumnFooter: true,
columnDefs: [{ name: 'H', width: '15%' }, { name: 'H1', width: '30%' }],
data: [
{ H: "", H1: "Brand name" },
{ H: " ", H1: "Molecule" },
{ H: "Product Details ", H1: "Therapeutic area" },
{ H: " ", H1: "Targeted indication " },
{ H: " ", H1: "Estimated size of the patient population (in your market) " }
],
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.core.on.renderingComplete(gridDrawn());
},
};
$scope.gridOptions.columnDefs.push({
name: 'H2', enableCellEdit: false,
field: "colButton", displayName: "Push Me",
//aggregationType: uiGridConstants.aggregationTypes.sum,
aggregationHideLabel: true,
cellTemplate: '<div><input type = "Number" placeholder = "Enter Number" onblur = "calculateTotal()" style = "width:90%" /></div>',
rowTemplate: '<div>Hai</div>',
width: '10%',
footerCellTemplate: '<div class = "ui-grid-cell-contents" >Total: {{col.getAggregationValue() | number:2 }}</div>'
});
function calculateTotal() {
alert("Hello");
gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
$scope.msg.lastCellEdited = 'edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue;
$scope.$apply();
});
}
определить переменную в области видимости, например: -
$scope.textboxValue = '';
затем добавьте переменную в ng-model
шаблона ячейки, как показано ниже.
cellTemplate: '<div><input type = "Number" ng-model = "textboxValue" placeholder = "Enter Number" onblur = "calculateTotal()" style = "width:90%" /></div>'
ваше значение текстового поля будет доступно в функции
$scope.calculateTotal = function () {
console.info($scope.textboxValue);
//other code
}