angular-ui / ui-grid

UI Grid: an Angular Data Grid
http://ui-grid.info
MIT License
5.39k stars 2.47k forks source link

GRID UI NOT showing VALUE #6716

Closed smarthotel123 closed 6 years ago

smarthotel123 commented 6 years ago

Grid ui not working my code is below

angular.module('myApp', ['ngAnimate', 'ui.bootstrap','ui.grid']);

angular.module('myApp').service('records', function() {

this.data = [{

}];

this.save = function(record) {

    this.data.push(record);
};

this.delete = function(index) {
    this.data.splice(index, 1);
};

});

angular.module('myApp').controller('HomeController', function($scope, $uibModal, records) { $scope.records=[{ 'date': '2018-04-18 00:00', 'place': 'Bangalore' },{ 'date': '2018-04-18 55:00', 'place': 'aaaaaaaa' }];

records.data= $scope.records;
$scope.records = records.data;

$scope.openModal = function(record) {
    $uibModal.open({
        resolve: {record: null},
        templateUrl: 'modal.html',
        controller: 'ModalController',
        backdrop: 'static'
    }).result.then(function(newRecord) {
        records.save(newRecord);
    });
};
 $scope.openModal1 = function(record) {
    $uibModal.open({
        resolve: {record: null},
        templateUrl: 'Test.html',
        controller: 'ModalController2',
        backdrop: 'static'
    }).result.then(function(newRecord) {
        records.save(newRecord);
    });
};

$scope.edit = function(record) {
    $uibModal.open({
        resolve: {
            record: record
        },
        templateUrl: 'modal.html',
        controller: 'ModalController',
         backdrop: 'static'
    }).result.then(function(updatedRecord) {
        angular.extend(record, updatedRecord);
    });
};

$scope.delete = function(index) {
  console.log(index + " in delete function");
  $uibModal.open({
    resolve: {record: index},
    template: '<div class="modal-body">' +
              '<button class="btn btn-danger" type="button" ng-click="deleteRecord(index)">delete</button>' +
              '<button class="btn btn-default" type="button" ng-click="cancel()">cancel</button>' +
              '</div>',
    controller: 'ModalController',
    backdrop: 'static'
  }).result.then(function(deleteIndex) {
    console.log(deleteIndex);
    records.delete(deleteIndex, 1);
  });
};

$scope.addwithinCtrl = function() {
    var record = {
        'date': new Date(),
        'place': 'Hyderabad'
    };
    records.save(record);
};

});

angular.module('myApp').controller('ModalController', function($scope, $uibModalInstance, record) {

$scope.record = angular.copy(record);

// save the input and dismiss the dialog
$scope.save = function() {
    if($scope.record.status=="fine"){

$uibModalInstance.close($scope.record); } else{ $scope.error="somwthing wents wrong"; }

};

$scope.cancel = function() {
    $uibModalInstance.dismiss('cancel');
};

$scope.deleteRecord = function() {
  $uibModalInstance.close($scope.record);
};

});

angular.module('myApp').directive('dateDirective', function() { return { scope: { model: '=ngModel' }, restrict: 'A', templateUrl: 'date.html', controller: function($scope) { $scope.format = 'yyyy-MM-dd HH:mm';

        $scope.open = function() {
            $scope.status.opened = true;
        };

        $scope.status = {
            opened: false
        };
    }
}

});

angular.module('myApp').controller('ModalController2', function($scope, $uibModalInstance, record) { $scope.gridOptions = {}; $scope.record = angular.copy(record); $scope.reset = reset; $scope.processbar=false;

function reset() { $scope.gridOptions.data = []; $scope.gridOptions.columnDefs = []; $scope.reset1 = "hhhhhhhhhhhhhhhhhh"; } // save the input and dismiss the dialog $scope.save = function() { if($scope.record.status=="fine"){

$scope.processbar=true; } else{ $scope.error="somwthing wents wrong"; }

};

$scope.cancel = function() {
    $uibModalInstance.dismiss('cancel');
};

$scope.deleteRecord = function() {
  $uibModalInstance.close($scope.record);
};

});

angular.module('myApp').directive('fileread', function() { return { scope: { opts: '=' }, link: function ($scope, $elm, $attrs) { $elm.on('change', function (changeEvent) { var reader = new FileReader();

    reader.onload = function (evt) {
      $scope.$apply(function () {
        var data = evt.target.result;

        var workbook = XLSX.read(data, {type: 'binary'});

        var headerNames = XLSX.utils.sheet_to_json( workbook.Sheets[workbook.SheetNames[0]], { header: 1 })[0];

        var data = XLSX.utils.sheet_to_json( workbook.Sheets[workbook.SheetNames[0]]);

        $scope.opts.columnDefs = [];
        headerNames.forEach(function (h) {
          $scope.opts.columnDefs.push({ field: h });
        });

        $scope.opts.data = data;

        $elm.val(null);
      });
    };

    reader.readAsBinaryString(changeEvent.target.files[0]);
  });
}

} });

mportuga commented 6 years ago

@smarthotel123 Please provide a plunker or code pen. As it is, I cannot debug this code. Also, please use stackoverflow or gitter for questions.

mportuga commented 6 years ago

Here is a plunker for you to use in your future queries: http://plnkr.co/edit/dLZtflGVWmg0wYXt9xMS?p=preview