0
votes

I'm using the smart-table with pagination. Also there is a default selected item (isSelected=true).

What I want to achieve is that the pagination goes to the actual page of the table where the selected item is.

I tried to get the $scope from the pagination, to access the selectPage() function.But I cannot get the $scope.

angular.element($('#pagination')).scope()

returns the controller $scope

angular.element($('#pagination')).isolatedScope()

returns null

Edit:

Here's the plnkr.

Is it possible to get the scope from a directive? I want the get the scope from this directive

Here's the table html:

<table st-table="table" st-pipe="pipeFunction" st-safe-src="rowCollection" class="table table-striped">
    ...
    <tfoot>
        <tr>
            <td colspan="5">
                <div id="pagination" st-pagination="" st-items-by-page="8" st-template="/scripts/angular/pagination.custom.html"></div>
            </td>
        </tr>
    </tfoot>
</table>
2
if you need an angular material one (I don't know what you need), then try this: github.com/iamisti/mdDataTable - Iamisti
@Iamisti the least thing i want is to replace the plugin, cause there is a lot working correctly - NinjaOnSafari
if you could provide an example in plunkr or codepen that would be great :) - Iamisti
Not very clear what you are trying to accomplish. Sounds like all you really need is a filter for isSelected - charlietfl
@charlietfl see the plnkr in the edited post. on init i want to see the selected item (red) on the last page. - NinjaOnSafari

2 Answers

1
votes

So I have managed it, also with the default selection.

javascript:

app.directive('stDefaultSelection', function () {
    return {
        require: 'stTable',
        restrict: 'A',
        scope: {
            selection: '=stDefaultSelection',
        },
        link: function link(scope, element, attrs, controller) {

            scope.$watch('selection', function (newValue, oldValue) {
                var selectionMode = 'single',
                    pagination = controller.tableState().pagination;

                //controller.select(newValue, selectionMode); => causes second call of function

                var rows = controller.getFilteredCollection(),
                    indexOfRow = rows.indexOf(newValue),
                    finalPage = Math.ceil(rows.length / pagination.number);

                if (indexOfRow > -1) {
                    controller.slice(finalPage * pagination.number, pagination.number);
                }
            });
        }
    };
});

html:

 `<table st-default-selection="selectedRow" st-table="table" st-safe-src="rowCollection"></table>`
0
votes

Ah I think I found the problem.

Instead of:

angular.element($('#pagination')).isolatedScope()

Try using (without a d):

angular.element($('#pagination')).isolateScope()