Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
I want to get datatables checkbox data from html template to views.py in django

I have used this example (https://jsfiddle.net/snqw56dw/3182/) to get checkboxes on my html table. I am getting the selected boxes data via the datatable script but I need to send this data to views.py on submission. I have used AJAX but it seems that I have been doing something wrong. Could you please help.

Javascript on html:

$(document).ready(function() {
var table1 = $('#pgnum').DataTable({     
    'columnDefs': [
    {
        'targets': 0,
        'checkboxes': {
        'selectRow': true
            }
        }
    ],
        'select': {
        'style': 'multi'
    },
        'order': [[1, 'asc']]
});

// Handle form submission event 
$('#eg').on('submit', function(e){
    var arr = [];
    var form = this;
    var rows_selected = table1.column(0).checkboxes.selected();
    // Iterate over all selected checkboxes
    $.each(rows_selected, function(index, rowId){
    // Create a hidden element
    arr.push(rowId);
    });
    $.ajax({
    type: "POST",
    url: "{% url 'add_user_eng' %}",
    data: {arr: 'arr'},
        });
    });   
});

urls.py

url(r'^eng_edit_admin/eng_add_user', views.add_user_eng, name='add_user_eng'),

views.py

def add_user_eng(request):
token = request.session['eng_id']
eng_id = str(token)
user_list = User.objects.all()
if request.method == 'POST':
    print("HELLO")
    print(request.POST.getlist('data[]'))
return render(request, 'main/add_user_to_engagement.html',{'user_list':user_list})

form id="eg" I am getting an empty list even when I submit or reload the page. Any sort of help is appreciated. Thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!