Fixes #3660 - Pagination for knowledge base answer sorting breaks sorting
This commit is contained in:
parent
0239bc14ab
commit
29f98be91f
3 changed files with 87 additions and 10 deletions
|
@ -4,6 +4,7 @@ class App.ControllerReorderModal extends App.ControllerModal
|
||||||
view = $(App.view('reorder_modal')())
|
view = $(App.view('reorder_modal')())
|
||||||
|
|
||||||
table = new App.ControllerTable(
|
table = new App.ControllerTable(
|
||||||
|
pager: false
|
||||||
baseColWidth: null
|
baseColWidth: null
|
||||||
dndCallback: ->
|
dndCallback: ->
|
||||||
true
|
true
|
||||||
|
|
|
@ -111,8 +111,9 @@ class App.ControllerTable extends App.Controller
|
||||||
groupBy: undefined
|
groupBy: undefined
|
||||||
groupDirection: undefined
|
groupDirection: undefined
|
||||||
|
|
||||||
shownPerPage: 150
|
pagerEnabled: true
|
||||||
shownPage: 0
|
pagerItemsPerPage: 150
|
||||||
|
pagerShownPage: 0
|
||||||
|
|
||||||
destroy: false
|
destroy: false
|
||||||
customActions: []
|
customActions: []
|
||||||
|
@ -197,6 +198,8 @@ class App.ControllerTable extends App.Controller
|
||||||
App.QueueManager.run('tableRender')
|
App.QueueManager.run('tableRender')
|
||||||
|
|
||||||
renderPager: (el, find = false) =>
|
renderPager: (el, find = false) =>
|
||||||
|
return if !@pagerEnabled
|
||||||
|
|
||||||
if @pagerAjax
|
if @pagerAjax
|
||||||
@renderPagerAjax(el, find)
|
@renderPagerAjax(el, find)
|
||||||
else
|
else
|
||||||
|
@ -220,7 +223,7 @@ class App.ControllerTable extends App.Controller
|
||||||
el.filter('.js-pager').html(pager)
|
el.filter('.js-pager').html(pager)
|
||||||
|
|
||||||
renderPagerStatic: (el, find = false) =>
|
renderPagerStatic: (el, find = false) =>
|
||||||
pages = parseInt(((@objects.length - 1) / @shownPerPage))
|
pages = parseInt(((@objects.length - 1) / @pagerItemsPerPage))
|
||||||
if pages < 1
|
if pages < 1
|
||||||
if find
|
if find
|
||||||
el.find('.js-pager').html('')
|
el.find('.js-pager').html('')
|
||||||
|
@ -228,7 +231,7 @@ class App.ControllerTable extends App.Controller
|
||||||
el.filter('.js-pager').html('')
|
el.filter('.js-pager').html('')
|
||||||
return
|
return
|
||||||
pager = App.view('generic/table_pager')(
|
pager = App.view('generic/table_pager')(
|
||||||
page: @shownPage
|
page: @pagerShownPage
|
||||||
pages: pages
|
pages: pages
|
||||||
)
|
)
|
||||||
if find
|
if find
|
||||||
|
@ -500,7 +503,7 @@ class App.ControllerTable extends App.Controller
|
||||||
groupLast = ''
|
groupLast = ''
|
||||||
groupLastName = ''
|
groupLastName = ''
|
||||||
tableBody = []
|
tableBody = []
|
||||||
objectsToShow = @objectsOfPage(@shownPage)
|
objectsToShow = @objectsOfPage(@pagerShownPage)
|
||||||
for object in objectsToShow
|
for object in objectsToShow
|
||||||
objectActions = []
|
objectActions = []
|
||||||
|
|
||||||
|
@ -663,13 +666,17 @@ class App.ControllerTable extends App.Controller
|
||||||
['new headers', @headers]
|
['new headers', @headers]
|
||||||
|
|
||||||
setMaxPage: =>
|
setMaxPage: =>
|
||||||
pages = parseInt(((@objects.length - 1) / @shownPerPage))
|
return if !@pagerEnabled
|
||||||
if parseInt(@shownPage) > pages
|
|
||||||
@shownPage = pages
|
pages = parseInt(((@objects.length - 1) / @pagerItemsPerPage))
|
||||||
|
if parseInt(@pagerShownPage) > pages
|
||||||
|
@pagerShownPage = pages
|
||||||
|
|
||||||
objectsOfPage: (page = 0) =>
|
objectsOfPage: (page = 0) =>
|
||||||
|
return @objects if !@pagerEnabled
|
||||||
|
|
||||||
page = parseInt(page)
|
page = parseInt(page)
|
||||||
@objects.slice(page * @shownPerPage, (page + 1) * @shownPerPage)
|
@objects.slice(page * @pagerItemsPerPage, (page + 1) * @pagerItemsPerPage)
|
||||||
|
|
||||||
paginate: (e) =>
|
paginate: (e) =>
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
@ -678,7 +685,7 @@ class App.ControllerTable extends App.Controller
|
||||||
@navigate "#{@pagerBaseUrl}#{(parseInt(page) + 1)}"
|
@navigate "#{@pagerBaseUrl}#{(parseInt(page) + 1)}"
|
||||||
else
|
else
|
||||||
render = =>
|
render = =>
|
||||||
@shownPage = page
|
@pagerShownPage = page
|
||||||
@renderTableFull()
|
@renderTableFull()
|
||||||
App.QueueManager.add('tableRender', render)
|
App.QueueManager.add('tableRender', render)
|
||||||
App.QueueManager.run('tableRender')
|
App.QueueManager.run('tableRender')
|
||||||
|
|
|
@ -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: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')
|
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)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue