angular.module('notely.filters').filter('pagination',
function () {
return function (elements, pagination) {
var filtered = [];
if (pagination) {
var begin, end, index;
begin = (pagination.current - 1) * pagination.limit;
end = begin + pagination.limit;
angular.forEach(elements, function (element) {
index = elements.indexOf(element);
if (begin <= index && index < end)
filtered.push(element);
});
} else {
return elements;
}
return filtered;
};
}
);
It displays the first 10 elements, even with the filterLogType so tis works fine. But rendering the pagination gives issues.
If you view the values of the pagination object I see the correct values but the pagination wouldn't render.
Is it because of the resouce I use to get the data from the API? And with the extra filter?
Any help is welcome, stuck with this for a few hours now!
Create resource js file and include this in your package manifest
Add factory
angular.module('notely.resources').factory('notelyResources',
function ($q, $http, umbRequestHelper) {
return {
// Get all elements
get: function (param) {
return umbRequestHelper.resourcePromise(
$http.get("path_to_the_api_controller", { params: { filter: param} }),
"Unable to get all the elements!"
);
},
};
}
);
Angularjs pagination issue custom plugin
Hi all,
I am building a new content section in the umbraco backoffice where I display a table which will contains some data.
To minify the rows I am implementing pagination using the
umb-pagination
directive.However this doesn't work and I do not see the pagination. If I use static valus in the directive then it works.
Below you can find all the code I use to get this to work..
View
Controller
Filters
It displays the first 10 elements, even with the
filterLogType
so tis works fine. But rendering the pagination gives issues.If you view the values of the pagination object I see the correct values but the pagination wouldn't render.
Is it because of the resouce I use to get the data from the API? And with the extra filter?
Any help is welcome, stuck with this for a few hours now!
/Michaël
UPDATE
Ok I got it working for the first time run.
It gives me the correct amount of pages in the pagination.
The reason is we need to update the pageNumber so that the directive re-runs because it contains a
$watch
on this property.But it doesn't has one for the totalPages.
Can we extend the directive to watch also on the totalPages to re-run the directive?
/Michaël
Ok solved.
Instead of filtering on client side I filter the results in the api and send these back.
Then totalPages and everything else gets updated.
/Michaël
Hi Michael, how are you filtering on the server? You pass the filter text to the server? Or is there a built-in service in Umbraco to help on that?
/Thanks :)
I pass the value of my filter as a param to my api controller.
Its even better this way then on the client side because else it needs to load in all of the data to do the filtering.
/Michaël
You can do this in the following way:
Add factory
/Michaël
Thanks for sharing :)
No problem Bilal!
Thats why we are here for!
/Michaël
Actually, I found this link, might give some more ideas also: http://24days.in/umbraco/2015/custom-listview/
/Bilal
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.