angularjs: ui-grid not renders more than 10 columns

你离开我真会死。 提交于 2020-01-01 12:14:55

问题


I have simple controller:

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')

When in looks like that (it have 10 columns), it looks fine.

But if I add one more column (or double any existing):

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

It becomes look like that:

So, it renders only 4 columns. But why? How to fix it?


回答1:


i have come with this issue and have solved it.

First, you should add ui-grid-auto-resize to your html:

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

Then, you should add ui.grid.autoResize to your 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')


来源:https://stackoverflow.com/questions/32346675/angularjs-ui-grid-not-renders-more-than-10-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!