Как пагинация данных json-ответа django - jquery

Я пытаюсь вывести на страницу данные JsonResponse от django, который является ajax вызовом, вот мой views.py

def lists(request):
    lists = CostType.objects.all().order_by('-pk')
    data = []
    for i in lists:
        item = {
            'id':i.id,
            'cost_type':i.cost_type,
            'admin':i.admin.username,
            'user':request.user.username,
        }
        data.append(item)
    return JsonResponse({'data':data})

я хочу показывать 10 сообщений на странице

и вот мой вызов ajax

function listCostTypes(){
    $.ajax({
        type:'GET',
        url:'/posts/list_posts',
        success:function(data){
          cost_types = data.data
        
          var k = '<tbody>'
          if(cost_types.length > 0){      
          for(i = 0;i < cost_types.length; i++){
            const id = parseInt(cost_types[i]['id'])
            k+= '<tr>';
              k+= '<td class="p-2 text-xs border border-purple-900 md:text-base textpurple">' + cost_types[i]['id'] + '</td>';
              k+= '<td class="p-2 text-xs border border-purple-900 md:text-base textpurple">' + cost_types[i]["admin"] + '</td>';
              k+= '<td class="p-2 text-xs border border-purple-900 md:text-base textpurple">' + cost_types[i]["cost_type"] + '</td>';
              k+= '</tr>'
          }
          }
          else{
            k+= '<td class="p-2 text-xs border border-purple-900 md:text-base textpurple" colspan=4>no data found</td>'
          }
          k+='</tbody>'            
          document.getElementById('types_list').innerHTML = k       
        },});}
      <table class="table table-bordered table-striped text-center" id="lists" >
        <thead>
        <tr>
          <th>#</th>
          <th>admin</th>          
          <th>costs</th>
        </tr>
        </thead>
        <tbody id="types_list">

        </tbody>

        </tfoot>
      </table>

Пожалуйста, есть ли возможность сделать пагинацию с данными JsonResponse ?! или объединить пагинацию бэкенда с пагинацией таблицы данных, пожалуйста ?! Заранее спасибо ..

Вернуться на верх