I am new to JavaScript and am having difficulty with this task. I am writing code to paginate a table I have. Right now all the logic related to buttons is hard coded and I want to make it more dynamic. Meaning, I have five buttons that all have separate code to do the same thing and I want to refactor my code so that I have n buttons and one script that controls them.
I want the code to generate (total records/number of records per page) number of buttons, then I want to take the value of that button and pass it into already existing code to grab the right section of the data table.
How do I do this though? All of the documentation I've found is for jQuery libraries like DataTables (which I spent like an hour working with and it did not display anything).
I would appreciate any tips, tricks, or tutorials.
EDIT
$(document).ready(function () {
$('#b1').click(function () {
var data = $("#isgeo").serializeArray();
data.push({ name: "page", value: '1' })
$.ajax({
type: 'GET',
url: '@Url.Action("GetTable", "SubsidencePoints")',
data: $.param(data),
cache: false,
processData: false,
contentType: false
}).done(function (result) {
$('#Sub-table').html(result);
});
$('#b2').click(function () {
var data = $("#isgeo").serializeArray();
data.push({ name: "page", value: '2' })
$.ajax({
type: 'GET',
url: '@Url.Action("GetTable", "SubsidencePoints")',
data: $.param(data),
cache: false,
processData: false,
contentType: false
}).done(function (result) {
$('#Sub-table').html(result);
});