diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee
index 1779c7d43..3087c1d2d 100644
--- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee
+++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee
@@ -226,7 +226,7 @@ class App.ControllerTable extends App.Controller
# check if order is still correct
if @_isSame(newRows, newCurrentRows) is true
- for position in removePositions
+ for position in removePositions.reverse()
@$("tbody > tr:nth-child(#{position+1})").remove()
@currentRows = newCurrentRows
console.log('fullRender.contentRemoved', removePositions)
@@ -534,7 +534,6 @@ class App.ControllerTable extends App.Controller
sortList: =>
return if _.isEmpty(@objects)
-
orderBy = @customOrderBy || @orderBy
orderDirection = @customOrderDirection || @orderDirection
@@ -549,7 +548,7 @@ class App.ControllerTable extends App.Controller
if orderBy
for header in @headers
- if header.name is orderBy || "#{header.name}_id" is orderBy# || header.name.substring(0, header.name.length - 3) is orderBy
+ if header.name is orderBy || "#{header.name}_id" is orderBy
localObjects = _.sortBy(
@objects
(item) ->
@@ -577,7 +576,40 @@ class App.ControllerTable extends App.Controller
header.sortOrderIcon = ['arrow-up', 'table-sort-arrow']
else
header.sortOrderIcon = undefined
- @objects = localObjects
+
+ # in case order by is not in show column, use orderBy attribute
+ if !localObjects
+ for attributeName, attribute of @attributesList
+ if attributeName is orderBy || "#{attributeName}_id" is orderBy
+
+ # order by
+ localObjects = _.sortBy(
+ @objects
+ (item) ->
+ # if we need to sort translated col.
+ if attribute.translate
+ return App.i18n.translateInline(item[attribute.name])
+
+ # if we need to sort by relation name
+ if attribute.relation
+ if item[attribute.name]
+ localItem = App[attribute.relation].findNative(item[attribute.name])
+ if localItem
+ if localItem.displayName
+ localItem = localItem.displayName().toLowerCase()
+ if localItem.name
+ localItem = localItem.name.toLowerCase()
+ return localItem
+ return ''
+ item[attribute.name]
+ )
+ if orderDirection is 'DESC'
+ localObjects = localObjects.reverse()
+
+ if localObjects
+ @objects = localObjects
+ else
+ console.log("Unable to orderBy objects, no attribute found with name #{orderBy}")
# group by
if @groupBy
diff --git a/public/assets/tests/table_extended.js b/public/assets/tests/table_extended.js
index fb8f38834..27395f53b 100644
--- a/public/assets/tests/table_extended.js
+++ b/public/assets/tests/table_extended.js
@@ -271,4 +271,191 @@ test('table new - initial list', function() {
equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Keine Einträge', 'check header')
equal(el.find('tbody > tr:nth-child(1) > td').length, 0, 'check row 1')
+ App.TicketPriority.refresh([
+ {
+ id: 1,
+ name: '1 low',
+ note: 'some note 1',
+ active: true,
+ created_at: '2014-06-10T11:17:34.000Z',
+ },
+ {
+ id: 3,
+ name: '3 high',
+ note: 'some note 3',
+ active: false,
+ created_at: '2014-06-10T10:17:38.000Z',
+ },
+ ], {clear: true})
+
+ result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'}), overviewAttributes: ['name'], orderBy: 'created_at', orderDirection: 'DESC'})
+ equal(result[0], 'fullRender')
+
+ equal(el.find('table > thead > tr').length, 1, 'row count')
+ equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
+ equal(el.find('table > thead > tr > th').length, 1, 'check header')
+ equal(el.find('tbody > tr:nth-child(1) > td').length, 1, 'check row 1')
+ equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
+ equal(el.find('tbody > tr:nth-child(2) > td').length, 1, 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '3 hoch', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td').length, 0, 'check row 3')
+
+ result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'}), overviewAttributes: ['name'], orderBy: 'created_at', orderDirection: 'ASC'})
+ equal(result[0], 'fullRender.overviewAttributesChanged')
+
+ equal(el.find('table > thead > tr').length, 1, 'row count')
+ equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
+ equal(el.find('table > thead > tr > th').length, 1, 'check header')
+ equal(el.find('tbody > tr:nth-child(1) > td').length, 1, 'check row 2')
+ equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '3 hoch', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(2) > td').length, 1, 'check row 1')
+ equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '1 niedrig', 'check row 1')
+ equal(el.find('tbody > tr:nth-child(3) > td').length, 0, 'check row 3')
+
+
+ $('#table').append('
table group by with data
')
+ var el = $('#table-new2')
+
+ App.TicketPriority.refresh([
+ {
+ id: 1,
+ name: '1 low',
+ note: 'some note',
+ active: true,
+ created_at: '2014-06-10T11:17:34.000Z',
+ },
+ {
+ id: 2,
+ name: '2 normal',
+ note: 'some note',
+ active: true,
+ created_at: '2014-06-10T10:17:30.000Z',
+ },
+ {
+ id: 3,
+ name: '3 high',
+ note: 'some other note',
+ active: true,
+ created_at: '2014-06-10T10:17:38.000Z',
+ },
+ ], {clear: true})
+
+ var table = new App.ControllerTable({
+ el: el,
+ overviewAttributes: ['name', 'created_at', 'active'],
+ model: App.TicketPriority,
+ objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'}),
+ checkbox: false,
+ radio: false,
+ groupBy: 'note',
+ })
+
+ equal(el.find('table > thead > tr').length, 1, 'row count')
+ equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
+ equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
+ equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
+ equal(el.find('tbody > tr:nth-child(1) > td').length, 1, 'check row 1')
+ equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), 'some note', 'check row 1')
+ equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '1 niedrig', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'true', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '2 normal', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:nth-child(3)').text().trim(), 'true', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(4) > td').length, 1, 'check row 3')
+ equal(el.find('tbody > tr:nth-child(4) > td:first').text().trim(), 'some other note', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(5) > td:first').text().trim(), '3 hoch', 'check row 5')
+ equal(el.find('tbody > tr:nth-child(5) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 5')
+ equal(el.find('tbody > tr:nth-child(5) > td:nth-child(3)').text().trim(), 'true', 'check row 5')
+ equal(el.find('tbody > tr:nth-child(6) > td').length, 0, 'check row 6')
+
+ result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
+ equal(result[0], 'noChanges')
+
+ App.TicketPriority.refresh([
+ {
+ id: 1,
+ name: '1 low',
+ note: 'some note',
+ active: true,
+ created_at: '2014-06-10T11:17:34.000Z',
+ },
+ {
+ id: 2,
+ name: '2 normal',
+ note: 'some note',
+ active: true,
+ created_at: '2014-06-10T10:17:30.000Z',
+ },
+ ], {clear: true})
+
+ result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
+ equal(result[0], 'fullRender.contentRemoved')
+
+ equal(el.find('table > thead > tr').length, 1, 'row count')
+ equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
+ equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
+ equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
+ equal(el.find('tbody > tr:nth-child(1) > td').length, 1, 'check row 1')
+ equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), 'some note', 'check row 1')
+ equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '1 niedrig', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'true', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '2 normal', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:nth-child(3)').text().trim(), 'true', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 6')
+
+ App.TicketPriority.refresh([
+ {
+ id: 1,
+ name: '1 low',
+ note: 'some note',
+ active: true,
+ created_at: '2014-06-10T11:17:34.000Z',
+ },
+ {
+ id: 2,
+ name: '2 normal',
+ note: 'some note',
+ active: true,
+ created_at: '2014-06-10T10:17:30.000Z',
+ },
+ {
+ id: 3,
+ name: '3 high',
+ note: 'some other note',
+ active: true,
+ created_at: '2014-06-10T10:17:38.000Z',
+ },
+ ], {clear: true})
+
+ result = table.update({sync: true, objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'})})
+ equal(result[0], 'fullRender.lenghtChanged')
+
+ equal(el.find('table > thead > tr').length, 1, 'row count')
+ equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
+ equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
+ equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
+ equal(el.find('tbody > tr:nth-child(1) > td').length, 1, 'check row 1')
+ equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), 'some note', 'check row 1')
+ equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '1 niedrig', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'true', 'check row 2')
+ equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '2 normal', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(3) > td:nth-child(3)').text().trim(), 'true', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(4) > td').length, 1, 'check row 3')
+ equal(el.find('tbody > tr:nth-child(4) > td:first').text().trim(), 'some other note', 'check row 3')
+ equal(el.find('tbody > tr:nth-child(5) > td:first').text().trim(), '3 hoch', 'check row 5')
+ equal(el.find('tbody > tr:nth-child(5) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 5')
+ equal(el.find('tbody > tr:nth-child(5) > td:nth-child(3)').text().trim(), 'true', 'check row 5')
+ equal(el.find('tbody > tr:nth-child(6) > td').length, 0, 'check row 6')
+
})