Fixes #3660 - Pagination for knowledge base answer sorting breaks sorting

This commit is contained in:
Mantas Masalskis 2021-08-12 12:08:50 +02:00
parent 0239bc14ab
commit 29f98be91f
3 changed files with 87 additions and 10 deletions

View file

@ -4,6 +4,7 @@ class App.ControllerReorderModal extends App.ControllerModal
view = $(App.view('reorder_modal')())
table = new App.ControllerTable(
pager: false
baseColWidth: null
dndCallback: ->
true

View file

@ -111,8 +111,9 @@ class App.ControllerTable extends App.Controller
groupBy: undefined
groupDirection: undefined
shownPerPage: 150
shownPage: 0
pagerEnabled: true
pagerItemsPerPage: 150
pagerShownPage: 0
destroy: false
customActions: []
@ -197,6 +198,8 @@ class App.ControllerTable extends App.Controller
App.QueueManager.run('tableRender')
renderPager: (el, find = false) =>
return if !@pagerEnabled
if @pagerAjax
@renderPagerAjax(el, find)
else
@ -220,7 +223,7 @@ class App.ControllerTable extends App.Controller
el.filter('.js-pager').html(pager)
renderPagerStatic: (el, find = false) =>
pages = parseInt(((@objects.length - 1) / @shownPerPage))
pages = parseInt(((@objects.length - 1) / @pagerItemsPerPage))
if pages < 1
if find
el.find('.js-pager').html('')
@ -228,7 +231,7 @@ class App.ControllerTable extends App.Controller
el.filter('.js-pager').html('')
return
pager = App.view('generic/table_pager')(
page: @shownPage
page: @pagerShownPage
pages: pages
)
if find
@ -500,7 +503,7 @@ class App.ControllerTable extends App.Controller
groupLast = ''
groupLastName = ''
tableBody = []
objectsToShow = @objectsOfPage(@shownPage)
objectsToShow = @objectsOfPage(@pagerShownPage)
for object in objectsToShow
objectActions = []
@ -663,13 +666,17 @@ class App.ControllerTable extends App.Controller
['new headers', @headers]
setMaxPage: =>
pages = parseInt(((@objects.length - 1) / @shownPerPage))
if parseInt(@shownPage) > pages
@shownPage = pages
return if !@pagerEnabled
pages = parseInt(((@objects.length - 1) / @pagerItemsPerPage))
if parseInt(@pagerShownPage) > pages
@pagerShownPage = pages
objectsOfPage: (page = 0) =>
return @objects if !@pagerEnabled
page = parseInt(page)
@objects.slice(page * @shownPerPage, (page + 1) * @shownPerPage)
@objects.slice(page * @pagerItemsPerPage, (page + 1) * @pagerItemsPerPage)
paginate: (e) =>
e.stopPropagation()
@ -678,7 +685,7 @@ class App.ControllerTable extends App.Controller
@navigate "#{@pagerBaseUrl}#{(parseInt(page) + 1)}"
else
render = =>
@shownPage = page
@pagerShownPage = page
@renderTableFull()
App.QueueManager.add('tableRender', render)
App.QueueManager.run('tableRender')

View file

@ -1705,4 +1705,73 @@ test('table new - initial list', function() {
equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '', 'check row 2')
$('#table').append('<hr><h1>table with large data and pager and 10 per page</h1><div id="table-new12"></div>')
var el = $('#table-new12')
var objects = [];
var created_at = Date.parse('2014-06-10T11:17:34.000Z')
for (i = 0; i < 35; i++) {
local_created_at = new Date(created_at - (1000 * 60 * 60 * 24 * i)).toISOString()
item = {
id: i,
name: i + ' prio',
note: 'some note',
active: true,
created_at: local_created_at,
}
objects.push(item)
}
App.TicketPriority.refresh(objects, {clear: true})
var table = new App.ControllerTable({
tableId: 'large_table_test_pager',
el: el,
overviewAttributes: ['name', 'created_at', 'active'],
model: App.TicketPriority,
objects: App.TicketPriority.all(),
checkbox: false,
radio: false,
pagerItemsPerPage: 10,
ttt: true
})
equal(el.find('tbody > tr').length, 10)
equal(el.find('.js-pager:first-child .js-page').length, 4)
$('#table').append('<hr><h1>table with large data and pager disabled</h1><div id="table-new13"></div>')
var el = $('#table-new13')
var objects = [];
var created_at = Date.parse('2014-06-10T11:17:34.000Z')
for (i = 0; i < 200; i++) {
local_created_at = new Date(created_at - (1000 * 60 * 60 * 24 * i)).toISOString()
item = {
id: i,
name: i + ' prio',
note: 'some note',
active: true,
created_at: local_created_at,
}
objects.push(item)
}
App.TicketPriority.refresh(objects, {clear: true})
var table = new App.ControllerTable({
tableId: 'large_table_test_pager',
el: el,
overviewAttributes: ['name', 'created_at', 'active'],
model: App.TicketPriority,
objects: App.TicketPriority.all(),
checkbox: false,
radio: false,
pagerEnabled: false,
ttt: true
})
equal(el.find('tbody > tr').length, 200)
equal(el.find('.js-pager:first-child .js-page').length, 0)
})