From 2ffe0d2efaded7c497997499347ed71fc05b2ad8 Mon Sep 17 00:00:00 2001 From: Felix Niklas Date: Thu, 22 Oct 2015 13:39:33 +0200 Subject: [PATCH] add sortByColumn method --- .../_application_controller_table.coffee | 24 ++++++++++++------- .../app/views/generic/table.jst.eco | 2 +- app/assets/stylesheets/zammad.scss | 4 ++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee index cfc8e8d73..f2b51dcc6 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee @@ -255,6 +255,10 @@ class App.ControllerTable extends App.Controller # enable resize column table.on 'mousedown', '.js-col-resize', @onColResizeMousedown + table.on 'click', '.js-col-resize', @stopPropagation + + # enable sort column + table.on 'click', '.js-sort', @sortByColumn # enable checkbox bulk selection if data.checkbox @@ -283,6 +287,9 @@ class App.ControllerTable extends App.Controller return table + stopPropagation: (event) => + event.stopPropagation() + onColResizeMousedown: (event) => @resizeTargetLeft = $(event.currentTarget).parents('th') @resizeTargetRight = @resizeTargetLeft.next() @@ -308,17 +315,18 @@ class App.ControllerTable extends App.Controller $(document).off 'mousemove.resizeCol' # switch to percentage resizeBaseWidth = @resizeTargetLeft.parents('table').width() - leftPercentage = (@resizeTargetLeft.outerWidth() / resizeBaseWidth) * 100 - rightPercentage = (@resizeTargetRight.outerWidth() / resizeBaseWidth) * 100 - - @resizeTargetLeft.width leftPercentage + '%' - @resizeTargetRight.width rightPercentage + '%' + leftWidth = @resizeTargetLeft.outerWidth() + rightWidth= @resizeTargetRight.outerWidth() leftColumnKey = @resizeTargetLeft.attr('data-column-key') rightColumnKey = @resizeTargetRight.attr('data-column-key') # save table changed widths # @storeColWidths [ - # { key: leftColumnKey, width: leftPercentage } - # { key: rightColumnKey, width: rightPercentage } - # ] \ No newline at end of file + # { key: leftColumnKey, width: leftWidth } + # { key: rightColumnKey, width: rightWidth } + # ] + + sortByColumn: (event) => + column = $(event.currentTarget).closest('[data-column-key]').attr('data-column-key') + # sort \ No newline at end of file diff --git a/app/assets/javascripts/app/views/generic/table.jst.eco b/app/assets/javascripts/app/views/generic/table.jst.eco index e02658a72..7460ec68a 100644 --- a/app/assets/javascripts/app/views/generic/table.jst.eco +++ b/app/assets/javascripts/app/views/generic/table.jst.eco @@ -15,7 +15,7 @@ <% end %> <% for item, i in @header: %> <%= " style='#{ item.style }'" if item.style %> data-column-key="<%= item.name %>"> -
+
<%- @T( item.display ) %> <% if item.sortOrderIcon: %> <%- @Icon(item.sortOrderIcon[0], item.sortOrderIcon[1]) %> diff --git a/app/assets/stylesheets/zammad.scss b/app/assets/stylesheets/zammad.scss index c8f3134d7..5d7a17f52 100644 --- a/app/assets/stylesheets/zammad.scss +++ b/app/assets/stylesheets/zammad.scss @@ -699,6 +699,10 @@ table { box-sizing: content-box; } +.table-column-title { + cursor: pointer; +} + .table > tbody > tr > td { padding: 11px 10px 7px; border: none;