django-el-pagination: Pagination on scroll don't work after AJAX update?
I use pagination on scroll in my project.
I show list of documents to user. Every such document has edit button. When user click to edit button he can see edit form. After successful editing I update list by AJAX. Problem is that after AJAX update the list pagination don’t work anymore. In browser console I notice this error:
TypeError: fragment.trim is not a function | el-pagination.js:72:50
Usually I see such url in pagination on scroll:
GET /documents/?page=2&querystring_key=page HTTP/1.1" 200 95118
But when I try to scroll in updated list I see in terminal next url:
GET /documents/2225/edit/?page=2&querystring_key=page HTTP/1.1" 200 6230
It seems to me that I need to update/refresh pagination script in crud.js file. I put activatePagination
function inside crud.js file but it didn’t help me. Can you help me to fix this problem?
main_template.html:
<div id="documents" class="dd">
<ol class="dd-list">
{% include page_template %}
</ol>
</div>
{% block script %}
{# START: AJAX request to endless pagination #}
<script type="text/javascript">
function activatePagination(){
$.endlessPaginate({
paginateOnScroll: true,
onCompleted: function(context, fragment) {
activateTooltip();
}
});
}
activatePagination();
</script>
{# END: AJAX request to endless pagination #}
<script src="{% static 'js/documents/crud.js'%}"></script> {# CRUD JS #}
{% endblock %}
crud.js:
$(function () {
$("#document-modal").on("submit", ".document-edit-form", function(e) {e.preventDefault(); saveForm.call(this, "Data successfully updated");});
var saveForm = function(success_message) {
var form = $(this);
var formData = new FormData(form[0]);
$.ajax({
url: form.attr("action"),
data: formData,
type: form.attr("method"),
dataType: 'json',
success: function (data) {
if (data.form_is_valid) {
// Update list of documents
$("#documents ol.dd-list").html(data.html_documents);
activatePagination();
// Hide modal
$("#document-modal").modal("hide");
// Show message to user
$("#user-action-message").fadeIn("slow");
setTimeout(function() {$("#user-action-message").fadeOut("slow");}, 2000);
}
},
cache: false,
contentType: false,
processData: false,
});
return false;
};
});
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (5 by maintainers)
Maybe it can helps:
I also thought about it. Could you describe your idea in more detail? That idea seems great but I don’t know how to realize it. I mean how for example to know current page / documents of current page. I would be very grateful if you show your idea with some code or some advises how to reorganize my
views.py
file in this case 😉By the way I think it would be better to to set id of document like this in template:
<div class="list-group-item" data-id="{{document.id}}">{{document.title}}</div>