Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
963 views
in Technique[技术] by (71.8m points)

angularjs - Smart-table - Setting page from code

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...