Smart-table - Setting page from code

╄→尐↘猪︶ㄣ 提交于 2019-12-28 18:13:12

问题


I'm using the very good table library Smart-table to display my data.

I am using a custom pagination template. I would however like to be able to set page 1 from the code. I have read up on the st-pipe directive it exposes, but it seems that I would need to re-write the whole filtering/pagination/sorting code myself if I implement that.

I'm after a simple way to programatically set a page from outside of the st-pagination directive that exists in my table's tfoot

<table st-table="displayedCollection" st-safe-src="tags" class="table table-hover">
    <tbody>
        <tr st-select-row="tag" st-select-mode="single" ng-repeat="tag in displayedCollection" ng-click="click(tag)">
            <td>
                <span editable-text="tag.name" e-placeholder="enter a display name..." e-name="name" e-form="editableForm" e-required>
                {{tag.name}}</span>
            </td>
            <td>
                <span editable-text="tag.path" e-placeholder="enter actual value to be used..." e-name="path" e-form="editableForm" e-required>
                {{tag.path}}</span>
            </td>
            <td>
                <form editable-form shown="newItem == tag" onshow="onShow()" name="editableForm" oncancel="oncancel(newItem)" onaftersave="saveForm(tag)">
                    <!-- EDIT -->
                    <button type="button" class="btn btn-sm btn-default" ng-click="editableForm.$show()" tooltip="Edit" tooltip-placement="left" ng-hide="editableForm.$visible">
                        <i class="fa fa-pencil-square-o fa-lg"></i>
                    </button>
                </form>
            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="1" class="text-left">
                <div st-template="app/partials/pagination.html" st-pagination="" st-items-by-page="pager.itemsOnPage"></div>
            </td>
            <td colspan="1">
                <div class="btn-group btn-group-sm pull-right ng-scope">
                    <button type="button" ng-class="{'active':pager.itemsOnPage==5}" ng-click="pager.itemsOnPage=5" class="btn btn-default">5</button>
                    <button type="button" ng-class="{'active':pager.itemsOnPage==10}" ng-click="pager.itemsOnPage=10" class="btn btn-default">10</button>
                    <button type="button" ng-class="{'active':pager.itemsOnPage==20}" ng-click="pager.itemsOnPage=20" class="btn btn-default">20</button>
                    <button type="button" ng-class="{'active':pager.itemsOnPage==30}" ng-click="pager.itemsOnPage=30" class="btn btn-default">30</button>
                </div>
            </td>
        </tr>
    </tfoot>
</table>

I'd like to be able to set page on from the <form> sections onshow directive.

Does anyone know if this is possible? Many thanks.


回答1:


To set the angular-smart-table page number from code use st-pagination's selectPage() function.

Where your HTML has a paginator element like this:

<div id="pagerId" st-pagination="" st-items-by- ...

You could use code like this in your directive

function setPage(pageNumber)
{
    angular
       .element( $('#pagerId') )
       .isolateScope()
       .selectPage(pageNumber);
}

You need to have jQuery installed to use $. I got the idea from the last example on: http://lorenzofox3.github.io/smart-table-website/



来源:https://stackoverflow.com/questions/29921339/smart-table-setting-page-from-code

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