2017-01-31 4 views
0

나는 handsontable을 문자열로 바꾸는 코드 조각을 가지고 있습니다 : JSBin. handsontable에서 셀 값을 변경하면 해당 문자열이 변경됩니다.handsontable에서 숫자를 숫자 형식으로 처리하게하십시오

<html ng-app="app"> 
    <head> 
    <script src="https://handsontable.github.io/ngHandsontable/node_modules/angular/angular.js"></script> 
    <script src="https://docs.handsontable.com/pro/1.8.2/bower_components/handsontable-pro/dist/handsontable.full.js"></script> 
    <link type="text/css" rel="stylesheet" href="https://docs.handsontable.com/pro/1.8.2/bower_components/handsontable-pro/dist/handsontable.full.min.css"> 
    <script src="https://handsontable.github.io/ngHandsontable/dist/ngHandsontable.js"></script> 
    </head> 
    <body> 
    <div ng-controller="MainCtrl"> 
     <hot-table hot-id="mytable" datarows="db"></hot-table> 
     <br><br> 
     <span>{{ data }}</span> 
    </div> 
    </body> 
</html> 

자바 스크립트 : 우리는 테이블에 새로운 숫자 값을 넣으면

function MainCtrl($scope, hotRegisterer) { 
    $scope.db = [[5, 6], [7, 8]]; 

    $scope.$watch("db", function (newValue, oldValue) { 
    console.log("$watch"); 
    var hot_instance = hotRegisterer.getInstance("mytable"); 
    $scope.data = hot_instance.getData(); 
    }, true) 
} 
MainCtrl.$inject = ['$scope', 'hotRegisterer']; 

angular.module('app', ['ngHandsontable']) 
    .controller('MainCtrl', MainCtrl) 

그러나, 다른 값으로 정렬되지 않은 배열의 문자열로 간주됩니다 배열의 형식.

handsontbale이 모든 셀 값을 기본적으로 문자열 유형으로 처리하는 이유를 알지 못합니다. 그러한 새로운 설정 방법이 있습니까 숫자 세포 값은 숫자 유형으로 처리됩니까?

편집 1 : @acesmndr의 대답에이어서 this을 작성했습니다. 그리고 난수를 db에 추가하여 setting.columns을 열의 수에 따라 업데이트하고 싶습니다. 그러나, 나는 우리가 settings.columns 설정하면, 우리는 추가 할 수 없습니다 것을 깨닫게 /를 contexte 메뉴가 더 이상 열을 제거 :

enter image description here

사람이 해결책이 있습니까?

답변

0

숫자로 된 열의 설정을 지정해야합니다. 다음의 작업 스냅 샷은 당신의 jsbin

분명히 당신은 내가이 편집 이전에 제안 된 열 수준 설정과는 달리 열을 추가하거나 제거 할 수 있도록 전체 테이블에 대해 적용되는 기본 설정 객체의 typeinvalidCellClassName 설정을 설정 해제하는 열 추가 또는 제거. 전체 테이블의 설정을 사용하여 jsbin의 업데이트 된 스냅 샷 here

function MainCtrl($scope, hotRegisterer) { 
    $scope.db = [[5, 6], [7, 8]]; 
    $scope.settings = { 
    type: 'numeric', 
    invalidCellClassName: 'someCssClass' 
    }; 
    $scope.$watch("db", function (newValue, oldValue) { 
    console.log("$watch"); 
    var hot_instance = hotRegisterer.getInstance("mytable"); 
    $scope.data = hot_instance.getData(); 
    }, true) 
} 
MainCtrl.$inject = ['$scope', 'hotRegisterer']; 

angular.module('app', ['ngHandsontable']) 
    .controller('MainCtrl', MainCtrl) 

입니다 그리고 나는 열 수를 모르는)을 hot-table

<hot-table hot-id="mytable" datarows="db" settings="settings"></hot-table> 
+0

1로 설정을 추가하는 방식이있다 전체 테이블'type : 'numeric''; 1)이 설정에서 셀에 문자열'abc'를 입력하면 배경색이 빨간색으로 바뀌는 것을 어떻게 알 수 있습니까? 문자열에 오류나 경고를 발생시키고 싶지 않습니다. –

+0

'invalidCellClassName'을 추가하여 무효화 된 셀의 CSS를 정의 할 수 있습니다. 그래서 이것을 사용하지 않으려면'{type : 'numeric', invalidCellClassName : 'someCssClass'}'클래스 이름을 추가하십시오. 전체 테이블을 설정하기 위해 더 쉬운 방법이 존재하는지는 모르지만'$ scope.db' 배열 요소의 길이를 반복하여'$ scope.settings.columns ' – acesmndr

+0

내 업데이트를 참조하십시오 ... –