Passing Parameter in URL to DataTables controllers

Passing Parameter in URL to DataTables controllers

trlt48trlt48 Posts: 2Questions: 1Answers: 0

I'm working on a server side processing DataTables (with Spring MVC), the following works as expected:

URL: http://localhost:8080/directory.html

datatable.js
$(document).ready( function () {
var table = $('#directoryTable').DataTable({
serverSide: true,
ajax: {
"url": "/employees",
.....
}
});

controller:
@RestController
public class EmployeeRestController {
@RequestMapping(value = "/employees", method = RequestMethod.POST)
@ResponseBody
public String listEmployeePaginated(HttpServletRequest request, HttpServletResponse response, Model model) {
.....
}
}

Questions: How to process the same URL with an added parameter:
http://localhost:8080/directory.html?affiliation=student

I can't figure out how to pass the parameter (affiliation=student) to datatable.js to be received and processed by the controller?

New to Spring MVC and DataTables. Any help is greatly appreciated. Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    I can't help you with the Spring part, but if you want to pass a query string along in an Ajax request you can use ajax.data along with window.location's search parameter.

    Allan

  • trlt48trlt48 Posts: 2Questions: 1Answers: 0

    Thanks for the hints! Using your suggestions solved the problem that I've been struggling with!

This discussion has been closed.