angularjs: ui-grid not renders more than 10 columns
Asked Answered
M

1

5

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. Correct view

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

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

It becomes look like that: enter image description here

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

Mora answered 2/9, 2015 at 7:9 Comment(2)
Can you create a plunker?Gwinn
plnkr.co/edit/B2XvXChL6mY4fpiFUkVe?p=preview But now it works fine. WTF in my case...?Mora
M
8

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')
Modla answered 9/12, 2015 at 7:48 Comment(3)
Yay, thank you very much! I will try your solution soon =)Mora
@VinoDang - Thanks, you've just fixed the exact problem I was facing! No more headache :-)Jennette
Thank you very much. Any idea why this happens and why this solves it? What's so magical about number 10 in this case?..Finicky

© 2022 - 2024 — McMap. All rights reserved.