diff --git a/app/assets/javascripts/app/controllers/_application_controller/table.coffee b/app/assets/javascripts/app/controllers/_application_controller/table.coffee index 809c767f4..64e809fe3 100644 --- a/app/assets/javascripts/app/controllers/_application_controller/table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller/table.coffee @@ -504,24 +504,33 @@ class App.ControllerTable extends App.Controller groupLastName = '' tableBody = [] objectsToShow = @objectsOfPage(@pagerShownPage) - for object in objectsToShow - objectActions = [] + if @groupBy + # group by raw (and not printable) value so dates work also + objectsGrouped = _.groupBy(objectsToShow, (object) => object[@groupBy]) + else + objectsGrouped = { '': objectsToShow } - if object - position++ - if @groupBy - groupByName = @groupObjectName(object, @groupBy) - if groupLastName isnt groupByName - groupLastName = groupByName - tableBody.push @renderTableGroupByRow(object, position, groupByName) - for action in @actions - # Check if the available key is used, it can be a Boolean or a function which should be called. - if !action.available? || action.available == true - objectActions.push action - else if typeof action.available is 'function' && action.available(object) == true - objectActions.push action + for groupValue in Object.keys(objectsGrouped).sort() + groupObjects = objectsGrouped[groupValue] - tableBody.push @renderTableRow(object, position, objectActions) + for object in groupObjects + objectActions = [] + + if object + position++ + if @groupBy + groupByName = @groupObjectName(object, @groupBy) + if groupLastName isnt groupByName + groupLastName = groupByName + tableBody.push @renderTableGroupByRow(object, position, groupByName) + for action in @actions + # Check if the available key is used, it can be a Boolean or a function which should be called. + if !action.available? || action.available == true + objectActions.push action + else if typeof action.available is 'function' && action.available(object) == true + objectActions.push action + + tableBody.push @renderTableRow(object, position, objectActions) tableBody renderTableGroupByRow: (object, position, groupByName) => diff --git a/public/assets/tests/table.js b/public/assets/tests/table.js index b7eac8557..02ca59876 100644 --- a/public/assets/tests/table.js +++ b/public/assets/tests/table.js @@ -370,8 +370,8 @@ test('table test', function() { groupBy: 'priority', groupDirection: 'DESC', }) - equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), '2 normal', 'check row 1') - equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1)').text().trim(), '1 niedrig', 'check row 3') + equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), '1 niedrig', 'check row 1') + equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1)').text().trim(), '2 normal', 'check row 3') $('#table').append('