angularjs:ui-grid不会渲染超过10列

时间:2015-09-02 07:09:26

标签: angularjs coffeescript angular-ui-grid

我有简单的控制器:

angular.module('it.works', ['ngResource'])

  .controller 'ItWorksCtrl', ($scope, Task) ->
    $scope.worksTable = {
      data: Task.query(),
      columnDefs: [
        { field: "created_at", cellFilter: "date:'dd.MM.yyyy'", displayName: 'Дата создания' },
        { field: "task", cellFilter: "limitTo:300", displayName: 'Описание задачи' },
        { field: "performer", displayName: 'Исполнитель' },
        { field: "task_type", displayName: 'Срочность' },
        { field: "is_orgtechnik_task", displayName: 'Оргтехника', cellTemplate: "<div class='ui-grid-cell-contents'><i class='fa {{ COL_FIELD == true && \"fa-check\" }}'></i></div>" },
        { field: "department", displayName: 'Подразделение' },
        { field: "customer", displayName: 'Заказчик' },
        { field: "customer_telephone", displayName: 'Телефон заказчика' },
        { field: "end_date", displayName: 'Дата окончания', cellFilter: "date:'dd.MM.yyyy'" },
        { field: "task_status", displayName: 'Статус', cellTemplate: "<div class='ui-grid-cell-contents status-{{ COL_FIELD }}'>{{['В процессе выполнения', 'Выполнено', 'Невыполнимо'][COL_FIELD]}}</div>"}


      ]
    }

  .factory 'Task', ($resource) ->
    $resource('/api/it_works/:id.json')

当看起来像(它有10列),它看起来很好。 Correct view

但如果我再添加一列(或任何现有的两倍):

{ field: "performer", displayName: 'Исполнитель' },

看起来像那样: enter image description here

因此,它只渲染了4列。但为什么?如何解决?

1 个答案:

答案 0 :(得分:7)

我已经解决了这个问题并解决了它。

首先,您应该将ui-grid-auto-resize添加到您的html:

  <div ui-grid="gridOptions" ui-grid-pagination ui-grid-resize-columns ui-grid-auto-resize
                    ui-grid-selection class="grid"></div>

然后,您应该将ui.grid.autoResize添加到您的js:

angular.module('it.works', ['ngResource','ngAnimate', 'ngSanitize',  'ui.grid', 'ui.grid.pagination','ui.grid.autoResize','ui.grid.selection', 'ui.grid.resizeColumns'])

  .controller 'ItWorksCtrl', ($scope, Task) ->
    $scope.worksTable = {
      data: Task.query(),
      columnDefs: [
        { field: "created_at", cellFilter: "date:'dd.MM.yyyy'", displayName: 'Дата создания' },
        { field: "task", cellFilter: "limitTo:300", displayName: 'Описание задачи' },
        { field: "performer", displayName: 'Исполнитель' },
        { field: "task_type", displayName: 'Срочность' },
        { field: "is_orgtechnik_task", displayName: 'Оргтехника', cellTemplate: "<div class='ui-grid-cell-contents'><i class='fa {{ COL_FIELD == true && \"fa-check\" }}'></i></div>" },
        { field: "department", displayName: 'Подразделение' },
        { field: "customer", displayName: 'Заказчик' },
        { field: "customer_telephone", displayName: 'Телефон заказчика' },
        { field: "end_date", displayName: 'Дата окончания', cellFilter: "date:'dd.MM.yyyy'" },
        { field: "task_status", displayName: 'Статус', cellTemplate: "<div class='ui-grid-cell-contents status-{{ COL_FIELD }}'>{{['В процессе выполнения', 'Выполнено', 'Невыполнимо'][COL_FIELD]}}</div>"}


      ]
    }

  .factory 'Task', ($resource) ->
    $resource('/api/it_works/:id.json')