ui-datepicker를 포함하도록 ui-grid에서 editableCellTemplate을 업데이트하려고합니다. 따라서 사용자가 firefox 또는 IE를 사용하여 날짜를 선택할 수 있도록 허용하지만 아니요 성공. 여기에 이 있습니다. 사용하는 방법은 editableCellTemplate: '<div style="display:inline-block; min-height:290px; position:absolute;"><div uib-datepicker class="well well-sm" datepicker-options="dateOptions" ng-focus="open()" style="background-color: #f5f5f5; border: 1px solid #e3e3e3; border-radius: 0; padding: 8px;" >'
입니다.ui-grid 문제가있는 ui-datepicker
0
A
답변
2
여기에 모든 세부 정보와 옵션이 포함 된 ui-datepicker 지시문이있는 예가 나와 있습니다.
이var app = angular.module('ui.grid.edit');
app.directive('uiGridEditDatepicker', ['$timeout', '$document', 'uiGridConstants', 'uiGridEditConstants', function($timeout, $document, uiGridConstants, uiGridEditConstants) {
return {
template: function(element, attrs) {
var html = '<div class="datepicker-wrapper" ><input type="text" uib-datepicker-popup datepicker-options="datepickerOptions" datepicker-append-to-body="true" is-open="isOpen" ng-model="datePickerValue" ng-change="changeDate($event)" popup-placement="auto top"/></div>';
return html;
},
require: ['?^uiGrid', '?^uiGridRenderContainer'],
scope: true,
compile: function() {
return {
pre: function($scope, $elm, $attrs) {
if ($attrs.datepickerOptions){
if ($scope.col.grid.appScope[$attrs.datepickerOptions]){
$scope.datepickerOptions = $scope.col.grid.appScope[$attrs.datepickerOptions];
}
}
},
post: function($scope, $elm, $attrs, controllers) {
var setCorrectPosition = function() {
var gridElement = $('.ui-grid-viewport');
var gridPosition = {
width: gridElement.outerWidth(),
height: gridElement.outerHeight(),
offset: gridElement.offset()
};
var cellElement = $($elm);
var cellPosition = {
width: cellElement.outerWidth(),
height: cellElement.outerHeight(),
offset: cellElement.offset()
};
var datepickerElement = $('body > .dropdown-menu, body > div > .dropdown-menu');
var datepickerPosition = {
width: datepickerElement.outerWidth(),
height: datepickerElement.outerHeight()
};
var setCorrectTopPositionInGrid = function() {
var topPosition;
var freePixelsOnBottom = gridPosition.height - (cellPosition.offset.top - gridPosition.offset.top) - cellPosition.height;
var freePixelsOnTop = gridPosition.height - freePixelsOnBottom - cellPosition.height;
var requiredPixels = (datepickerPosition.height - cellPosition.height)/2;
if (freePixelsOnBottom >= requiredPixels && freePixelsOnTop >= requiredPixels) {
topPosition = cellPosition.offset.top - requiredPixels + 10;
} else if (freePixelsOnBottom >= requiredPixels && freePixelsOnTop < requiredPixels) {
topPosition = cellPosition.offset.top - freePixelsOnTop + 10;
} else {
topPosition = gridPosition.height - datepickerPosition.height + gridPosition.offset.top - 20;
}
return topPosition;
};
var setCorrectTopPositionInWindow = function() {
var topPosition;
var windowHeight = window.innerHeight - 10;
var freePixelsOnBottom = windowHeight - cellPosition.offset.top;
var freePixelsOnTop = windowHeight - freePixelsOnBottom - cellPosition.height;
var requiredPixels = (datepickerPosition.height - cellPosition.height)/2;
if (freePixelsOnBottom >= requiredPixels && freePixelsOnTop >= requiredPixels) {
topPosition = cellPosition.offset.top - requiredPixels;
} else if (freePixelsOnBottom >= requiredPixels && freePixelsOnTop < requiredPixels) {
topPosition = cellPosition.offset.top - freePixelsOnTop;
} else {
topPosition = windowHeight - datepickerPosition.height - 10;
}
return topPosition;
};
var newOffsetValues = {};
var isFreeOnRight = (gridPosition.width - (cellPosition.offset.left - gridPosition.offset.left) - cellPosition.width) > datepickerPosition.width;
if (isFreeOnRight) {
newOffsetValues.left = cellPosition.offset.left + cellPosition.width;
} else {
newOffsetValues.left = cellPosition.offset.left - datepickerPosition.width;
}
if (datepickerPosition.height < gridPosition.height) {
newOffsetValues.top = setCorrectTopPositionInGrid();
} else {
newOffsetValues.top = setCorrectTopPositionInWindow();
}
datepickerElement.offset(newOffsetValues);
datepickerElement.css("visibility", "visible");
};
$timeout(function() {
setCorrectPosition();
}, 0);
$scope.datePickerValue = new Date($scope.row.entity[$scope.col.field]);
$scope.isOpen = true;
var uiGridCtrl = controllers[0];
var renderContainerCtrl = controllers[1];
var onWindowClick = function (evt) {
var classNamed = angular.element(evt.target).attr('class');
if (classNamed) {
var inDatepicker = (classNamed.indexOf('datepicker-calendar') > -1);
if (!inDatepicker && evt.target.nodeName !== "INPUT") {
$scope.stopEdit(evt);
}
}
else {
$scope.stopEdit(evt);
}
};
var onCellClick = function (evt) {
angular.element(document.querySelectorAll('.ui-grid-cell-contents')).off('click', onCellClick);
$scope.stopEdit(evt);
};
$scope.changeDate = function (evt) {
$scope.row.entity[$scope.col.field] = $scope.datePickerValue;
$scope.stopEdit(evt);
};
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function() {
if (uiGridCtrl.grid.api.cellNav) {
uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol) {
$scope.stopEdit();
});
} else {
angular.element(document.querySelectorAll('.ui-grid-cell-contents')).on('click', onCellClick);
}
angular.element(window).on('click', onWindowClick);
});
$scope.$on('$destroy', function() {
angular.element(window).off('click', onWindowClick);
$('body > .dropdown-menu, body > div > .dropdown-menu').remove();
});
$scope.stopEdit = function(evt) {
$scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
};
$elm.on('keydown', function(evt) {
switch (evt.keyCode) {
case uiGridConstants.keymap.ESC:
evt.stopPropagation();
$scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
break;
}
if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId;
if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) {
$scope.stopEdit(evt);
}
} else {
switch (evt.keyCode) {
case uiGridConstants.keymap.ENTER:
case uiGridConstants.keymap.TAB:
evt.stopPropagation();
evt.preventDefault();
$scope.stopEdit(evt);
break;
}
}
return true;
});
}
};
}
};
}]);
이 plunker를 살펴 : 아래와 같은 UI를-날짜 선택기 지시자가 보이는 곳 이 github link이 plunker 예에서 자세한 내용을 확인할 수 있습니다 http://plnkr.co/edit/4mNr86cN6wFOLYQ02QND?p=preview – Yaser
@ Yaser는이 업데이트에 대해 많이 감사합니다. 그러나이 경우 캘린더 옵션을 처리하는 방법을 알고 있습니까? 최소 및 최대 날짜를 변경하려면 아이디어가 있습니까? '$ scope.dateOptions = { formatYear : 'yy', maxDate : new Date (2020, 5, 22), minDate : new Date(), startingDay : 1 } – Med