I want to integrate the bootstrap-table plugin with server-side functionality using Django Rest Framework to populate the data on the table. However, I keep getting the message "No matching records found". After some investigation, I discovered that a specific format is required for the plugin to function properly (as outlined in the documentation: Note that the server response format varies depending on whether the 'client' or 'server' option is specified. Examples can be found here: Without server-side pagination, With server-side pagination). In my case, this is the code I am currently using:
1) serializers.py
from rest_framework import serializers
from .models import Datos
class DatosSerializer(serializers.ModelSerializer):
class Meta:
model = Datos
fields = (
'loteInsp',
'descripcion',
'fecha',
'material',
'batch',
'acepRech',
'resultado',
'limiteInferior',
'target',
'limiteSuperior',
)
2) views.py
from rest_framework import generics
from .models import Datos
from .serializers import DatosSerializer
class DatosViewSet(generics.ListAPIView):
queryset = Datos.objects.all().order_by('fecha')
serializer_class = DatosSerializer
3) urls.py
path('json/', DatosViewSet.as_view(), name='json'),
However, the server response that I receive looks like this in the console:
callback({"count":1064,"next":"http://127.0.0.1:8000/datos/json/?format=jsonp&limit=10&offset=0&order=asc&page=2&search=","previous":null,"results":[{"loteInsp":40004129308,"descripcion":"ALCANFOR P/P","fecha":"2015-01-03","material":15131132,"batch":"50602709L0","acepRech":true,"resultado":4.9,"limiteInferior":4.73,"target":5.26,"limiteSuperior":5.79},{"loteInsp":40004129308,"descripcion":"AC. DE EUCALIPTO P/P","fecha":"2015-01-03","material":15131132,"batch":"50602709L0","acepRech":true,"resultado":1.29,"limiteInferior":1.24,"target":1.33,"limiteSuperior":1.46},...
What modifications do I need to make to the serializer (or other components) to ensure that the response aligns with the required format for bootstrap-tables?
For example:
{
"total": 800,
"totalNotFiltered": 800,
"rows": [
{
"id": 0,
"name": "Item 0",
"price": "$0"
},
{
"id": 1,
"name": "Item 1",
"price": "$1"
},
{
"id": 2,
"name": "Item 2",
"price": "$2"
},
]
}
Thank you in advance for any suggestions or ideas.