How to add simple Where-clause with bookshelf-pagemaker

前端 未结 1 1445
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 21:24

Using the bookshelf-pagemaker NodeJS Module:

  • https://www.npmjs.com/package/bookshelf-pagemaker
  • https://github.com/bhoriuchi/bookshelf-pag
相关标签:
1条回答
  • 2021-01-24 21:54

    I have added support for this in the freshly published version 0.1.3. You can now supply a where statement to the args object you pass to the paginate function. the sql statement you supply will be added with an and to the filter sql so you will still be able to use search functionality

    your args object would look like

        var args = {
            params: {
                start: offset,
                page: pageNum,
                length: pageSize
            },
            model: UserDAO,
            where: '(id > 10 AND id < 100)'
        };

    var resultObj = pagemaker.datatables.paginate(args);
    
    resultObj.then(function (result) {
            paginateHandler(result);
        });
    }
    
    function paginateHandler (result) 
    {
        var numPaginatedRecords = result.recordsFiltered;
    
        var pagesTotal = Math.ceil(numPaginatedRecords / ITEMS_ON_PAGE);
    
        res.render('my_paginated_view', {
            data: result.data,
            currentPage: <from URL or default 1>,
            pagesCount: pagesTotal
        });
    };
    
    0 讨论(0)
提交回复
热议问题