l-lin / angular-datatables

DataTables with Angular
https://l-lin.github.io/angular-datatables/
MIT License
1.58k stars 486 forks source link

Serverside processing #989

Closed SpeedyH30 closed 6 years ago

SpeedyH30 commented 7 years ago

Now I’m probably being dim, and my head isn’t really with it. I’m creating a front end for a system, I can’t really touch the database but need to get data for viewing, and firing stored functions.

Any way it’s a MySQL db im running Knex.js Angular datatables .5.6 My issue is now that the users wish to have access to over 100,000 rows over data. They really don’t need it but who am I to argue. So I have to go server side processing, for pagination, filtering and searching. I have my knex

router.get(‘/all’, (req, res) =>  {
    db.select(‘foo’,
        ‘boo’,
        ‘boo’,
        ‘boo’,
    ).from('blah').limit(req.query.length).offset(req.query.length).then((data) +> res.json(data))
})

then my current js

app.controller('jobTableCtrl', jobTableCtrl);
function jobTableCtrl(DTOptionsBuilder, DTColumnBuilder, $scope, $filter) {
    var vm = this
    vm.dtOptions = DTOptionsBuilder.newoptions()
    .withOption('ajax', {
        dataSrc: '',
        url: 'api/all',
        data: function(res, settings){
            var api = new $.fn.dataTable.Api(settings);
            api.ajax.url(
                /api/all?start=' + res.start + '&length' + res.length
);
            vm.dtDraw = res.draw;
            return JSON.stringify(res)
    .withOption('processing', true)
    .withOption('serverside', true)
    .withOption('bpaginate', true)
    .withOption('aasorting',[1, desc'] )
    .withDisplayLength('30')
    .withOption('rowCallback', rowCallBack)

    vm.dtColumns = [

Any help would be appreciated

l-lin commented 7 years ago

What is your question? Is it about server side processing? Your server needs to return a specific object. See the DataTable official documentation for all needed returned data.