m12lrpv
m12lrpv

Reputation: 1287

bootstrap-table how do I add a custom request header when using server pagination

I've been using bootstrap table (http://bootstrap-table.wenzhixin.net.cn/) successfully in a typescript project for quite some time.

Unfortunately due to the amount of data returned for one table I want to switch to using server side pagination for that table.

For the most part that seems reasonably straightforward but I need the table to pass a custom request header to the server and cannot see how to do that.

The current headers are as below but I need to get the bootstrap table to add in an authorisation header containing the auth token.

http://localhost/api/1.0/LotsofData?order=asc&offset=0&limit=15&_=1542242900391

Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en;q=0.5
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
Host: localhost
Origin: http://localhost:53391
Pragma: no-cache
Referer: http://localhost:53391/
User-Agent: {stuff}

How do I add the custom request header to the bootstrap-table's get request Any assistance would be much appreciated.

Upvotes: 0

Views: 1178

Answers (1)

m12lrpv
m12lrpv

Reputation: 1287

Worked it out by searching for help on jquery $.ajax requests. You populate the ajaxOptions as shown in the code snippet.

...
url: controller.ourservice.build_url(scope.id1, scope.id2),
sidepagination: 'server',
ajaxOptions: { headers: { 'Authorization': 'Token ' + localStorage.getItem("access_token") }},
pageSize: 15,
pageList: [5, 15],
...

Upvotes: 1

Related Questions