ng-table icon indicating copy to clipboard operation
ng-table copied to clipboard

Pagination on top and bottom

Open gruskada opened this issue 12 years ago • 23 comments

I can't figure out how to get a pagination template to show up on the top and bottom of the table. In the source, if I try this:

return element.before(paginationTemplate).after("test");

the pagination template shows up before the table, and "test" shows up after, as expected.

But if I try this:

return element.before(paginationTemplate).after(paginationTemplate);

it only shows up after the table.

In any case, ideally there would be an attribute like pagination-location="top|bottom|topAndBottom" or something to that effect.

In the meantime, any ideas how to get this working by modifying the source?

gruskada avatar Jan 23 '14 18:01 gruskada

I just figured out one way to do it in the source - make two template variables, compile both, then reference the second one in after():

var paginationTemplate = angular.element(document.createElement('div')).attr('ng-include', 'templates.pagination'); var paginationTemplate2 = angular.element(document.createElement('div')).attr('ng-include', 'templates.pagination'); element.find('thead').remove(); var tbody = element.find('tbody'); element.prepend(headerTemplate); $compile(headerTemplate)(scope); $compile(paginationTemplate)(scope); $compile(paginationTemplate2)(scope); element.addClass('ng-table'); return element.before(paginationTemplate).after(paginationTemplate2);

gruskada avatar Jan 23 '14 18:01 gruskada

FTR if https://github.com/esvit/ng-table/pull/184 gets merged in you'll be able to do this with <table ng-table... pagination-top pagination-bottom>

anoek avatar Jan 25 '14 00:01 anoek

Awesome - thanks, anoek. I'll give it a try on Monday.

gruskada avatar Jan 25 '14 03:01 gruskada

Now you can place pagination in any place. Look example: https://github.com/esvit/ng-table/blob/master/examples/demo28.html#L28

esvit avatar Apr 12 '14 20:04 esvit

Even better. Thanks!

On Sat, Apr 12, 2014 at 4:47 PM, Vitalii Savchuk [email protected]:

Now you can place pagination in any place. Look example: https://github.com/esvit/ng-table/blob/master/examples/demo28.html#L28

Reply to this email directly or view it on GitHubhttps://github.com/esvit/ng-table/issues/182#issuecomment-40291352 .

gruskada avatar Apr 14 '14 01:04 gruskada

Hi everyone, I tried to use the v0.3.2 in order to display pagination on the top, but it didn't work, the console shows this message even in the example#28 provided:

TypeError: Cannot read property '$on' of null at link (file:///C:/Users/user/Desktop/ng-table-master/ng-table.js:690:47) at l (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:47:124) at f (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:41:361) at l (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:47:64) at f (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:41:361) at f (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:41:378) at file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:40:434 at file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:17:364 at h.$eval (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:105:313) at h.$apply (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:106:48)


at h.$apply (file:///C:/Users/user/Desktop/ng-table-master/examples/js/angular.min.js:106:48)

mpojeda84 avatar Jun 25 '14 22:06 mpojeda84

Hi, I'm getting the same issue as the above comment in a clean Angular + ngTable setting.

dcostaras avatar Jun 27 '14 10:06 dcostaras

I can't move the pagination above the table either. Can you be kind enough to show an example of placing the pagination on top? in demo28 it is still below the table

vizog avatar Jul 13 '14 08:07 vizog

In order to avoid the 'TypeError: Cannot read property '$on' of null', you need to add the $scope to the settings object:

$scope.tableParams = new ngTableParams({ page: 1, count: 10 }, { $scope: $scope, data: data });

ojacquemart avatar Aug 02 '14 13:08 ojacquemart

I ended up using

<table ng-table="tableParams" template-pagination="pagination" template-header="pagination" show-filter="false" class="table">

custom pagination template in both header and footer, hope it helps someone.

sahanh avatar Aug 26 '14 09:08 sahanh

@sahanh can you explain further how you got it to work? Where is the template defined?

realityfluxstudios avatar Sep 06 '14 12:09 realityfluxstudios

@realityfluxstudios you can define it within the page or external url https://gist.github.com/sahanh/8dda94cbca473ec71f48 when using external template provide the url for template-header

sahanh avatar Sep 06 '14 12:09 sahanh

@sahanh thank you! :)

realityfluxstudios avatar Sep 06 '14 15:09 realityfluxstudios

Are you guys able to align the pagination according to the requirement, because i'm not able to do it.

RohithAcharya avatar Sep 08 '14 11:09 RohithAcharya

@esvit - Thanks so much for your work on this, I'm incredibly grateful! However, I might need to abandon this module if I can't get pagination on top. I understand you probably have limited time, would you be willing to talk through how you want this coded if I were to contribute this as a feature?

I see on line 651 you have

element.addClass('ng-table')
                            .prepend(headerTemplate)
                            .after(paginationTemplate);

which makes this non-configurable for users. I think parsing the entire scope for an item with data-template-pagination is probably a bad practice, but perhaps we can just do a boolean here and add a tableParams.paginationPosition = {top || bottom} option so that we can get pagination above the table. If you want the pagination template it to be fully customizable, we could talk about how you'd like that to happen, but I'd love to help out if you need it!

brianfeister avatar Sep 19 '14 21:09 brianfeister

did anyone got this working?

deifos avatar Nov 13 '14 17:11 deifos

@gruskada Thanks that did the trick.

deifos avatar Nov 13 '14 17:11 deifos

Hi !

is this issue resolved ? Cause I use the version 1.0.0-beta.7, and there is no way to position the pagination on the top other than modify the directive code : $element.after(paginationTemplate); => $element.before(paginationTemplate); on the compileDirectiveTemplates function.

By the way, the demo28 is no longer present :'(

FrogDevelopper avatar Oct 23 '15 10:10 FrogDevelopper

@esvit What is the proper solution to display a pagination control at the top? You didn't merge https://github.com/esvit/ng-table/pull/184 and is referring to an out of date link to demo 28

justinr1234 avatar Apr 14 '16 18:04 justinr1234

I am also interested in how to easily and properly move the pagination controls to the top... any hint?

ghost avatar Apr 25 '16 14:04 ghost