How to add simple Where-clause with bookshelf-pagemaker

痴心易碎 提交于 2019-12-02 07:29:15
vbranden

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
    });
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!