Answer the question
In order to leave comments, you need to log in
Where does the second request come from when updating datatables?
Good evening! The essence of the vorpos is in the title. In a nutshell. I load the page and it loads the data ajax into the table. After I select some filters, I do ajax to the server, it filters there and gives back the dictionary. Everything works great here. But as soon as I try to rewrite the table with new data, another request is immediately made just like when loading the page, which returns all the data, and the table is already overwritten by a new request. In general, how to remove it ??? Or how to do filtering??? Please help, all the docks and all Google have already broken
html:
<table id="tableBid" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<!--<th>Аватар</th>-->
<th>Дата заявки</th>
<th>Страница отправки сообщения</th>
<th>Следующий шаг</th>
<th>Дата шага</th>
<th>Комментарий все</th>
<th>Имя</th>
<th>Телефон</th>
<th>е-meil</th>
</tr>
</thead>
</table>
var oTable = $('#tableBid').dataTable({
"processing": true, //При подгрузке страницы показывать таблицу или нет
"serverSide": true, // фильтрация на стороне сервера
"oLanguage": {
"sProcessing": "Подождите...",
"sLengthMenu": "_MENU_ записей на странице",
"sZeroRecords": "Записи отсутствуют.",
"sInfo": "Записи с _START_ до _END_ из _TOTAL_ записей",
"sInfoEmpty": "Записи с 0 до 0 из 0 записей",
"sInfoFiltered": "(отфильтровано из _MAX_ записей)",
"sInfoPostFix": "",
"sSearch": "Поиск: ",
"sUrl": "",
"oPaginate": {
"sFirst": "Первая",
"sPrevious": "Предыдущая",
"sNext": "Следующая",
"sLast": "Последняя"
},
},
"aoColumnDefs" : [{
"aTargets": [0],
"mRender": function(dataBid, type, full){
return dataBid.replace("T", " ").replace("Z", "");
}
},{
"aTargets": [2],
"mRender": function(status, type, full){
var str = '';
if (status == 1)
str = '<button name="1" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-info" id="bid-' + full[8] + '">Перезвонить</button>';
else if (status == 2)
str = '<button name="2" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-info" id="bid-' + full[8] + '">Отправить предложение</button>';
else if (status == 3)
str = '<button name="3" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-primary" id="bid-' + full[8] + '">Ожидаем ответа</button>';
else if (status == 4)
str = '<button name="4" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-danger" id="bid-' + full[8] + '">Отказ</button>';
else if (status == 5)
str = '<button name="5" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-warning" id="bid-' + full[8] + '">Ожидаем оплату</button>';
else if (status == 6)
str = '<button name="6" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-danger" id="bid-' + full[8] + '">Неккоректная заявка</button>';
else if (status == 7)
str = '<button name="7" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-info" id="bid-' + full[8] + '">Дублирующая заявка</button>';
else if (status == 8)
str = '<button name="8" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-danger" id="bid-' + full[8] + '">Удалено</button>';
else if (status == 9)
str = '<button name="9" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-primary" id="bid-' + full[8] + '">Дубл. захват</button>';
else if (status == 10)
str = '<button name="10" onclick="openPanel(' + full[8] + ', this);" style="width:190px" class="btn btn-success" id="bid-' + full[8] + '">Сделка завершена</button>';
return str;
}
},{
"aTargets": [3],
"mRender": function(dateStatus, type, full){
return dateStatus.replace("T", " ").replace("Z", "");
}
}
],
"ajax": "{% url 'bid.all.json' %}"
url(r'^table/json$', views.BidListView.as_view(), name='bid.all.json'),
url(r'^filtrbid/$', views.BidListView.filter_queryset, name='bid.filtr.json'),
class BidListView(BaseDatatableView):
model = bid
columns = ['dataBid', 'site.url', 'status', 'dateStatus', 'comment', 'name', 'number', 'email', 'id']
order_columns = ['dataBid', 'site.url', 'status', 'dateStatus', 'comment', 'name', 'number', 'email']
max_display_length = 250
def filter_queryset(self, qs):
if self.request.method == "POST":
search = self.request.POST['sitesFiltr']
if search:
qs = qs.filter(status=int(search))
return qs
else:
return qs
return qs
$.ajax({
url: "{% url 'bid.all.json' %}",
type: 'POST',
data: {
//sitesFiltr: filtrFFF,
},
dataType:"json",
error: function(data) {
oTable.fnClearTable();
oTable.fnAddData(data.data);
},
// При успехе меняем информацию в шаблоне
success: function(data){
oTable.fnClearTable();
oTable.fnAddData(data.data);
},
// CSRF механизм защиты Django
beforeSend: function(xhr, settings) {
console.log('-------------before send--');
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
}
});// ajax
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question