我的问题是我无法在搜索栏中搜索数据表中的特定记录(例如snumber)。浏览器引发错误:
DataTables警告:表ID =仓库-Ajax错误。有关此错误的更多信息,请参见http://datatables.net/tn/7
下面是我的代码。
我的观点
class ProductSerialNumbersListJSon(LoginRequiredMixin,BaseDatatableView):
# my model
model = ProductSerialNumbers
columns = ['snumber' , 'order','product','registration_date']
order_columns = ['snumber','order','product','registration_date']
max_display_length = 100
def get_initial_queryset(self):
print("FETCHED DATA")
#print(ProductSerialNumbers.objects.filter(Q(snumber__isnull=True)|Q(order_id__isnull=True)|Q (order_id__finished=0)).count())
return ProductSerialNumbers.objects.filter(Q(snumber__isnull=True)|Q(order_id__isnull=True)|Q (order_id__finished=0))
def render_column(self, row, column):
return super(ProductSerialNumbersListJSon, self).render_column(row, column)
我的模板
<script language="javascript">
$(document).ready(function () {
/* Here begins the DataTable configuration. */
$('#warehouse').DataTable({
/* Tell the DataTable that we need server-side processing. */
"serverSide": true,
"paging": true,
"pageLength": 10,
"processing": true,
"searching": true,
/* Set up the data source */
ajax: {
url: "{% url "warehouse_list_json" %}"
},
"columns":
[
{name: "snumber",},
{name: "order",},
{name: "product",},
{name: "registration_date",},
]
});
});
</script>
为了正确搜索,我在这里缺少什么?