Moved drawing the users datatable out of the addTarget method for faster rendering of a large number of imported records.

pull/414/merge
Jordan Wright 2016-11-18 22:16:32 -06:00
parent 43cbc1d65f
commit b10ac627af
1 changed files with 10 additions and 6 deletions

View File

@ -100,6 +100,7 @@ function edit(idx) {
record.email, record.email,
record.position); record.position);
}); });
targets.DataTable().draw();
} }
}) })
} }
@ -128,19 +129,21 @@ function addTarget(firstNameInput, lastNameInput, emailInput, positionInput) {
// Check table to see if email already exists. // Check table to see if email already exists.
var targetsTable = targets.DataTable(); var targetsTable = targets.DataTable();
var existingRowIndex = targetsTable var existingRowIndex = targetsTable
.column(2, {order: "index"}) // Email column has index of 2 .column(2, {
order: "index"
}) // Email column has index of 2
.data() .data()
.indexOf(email); .indexOf(email);
// Update or add new row as necessary. // Update or add new row as necessary.
if (existingRowIndex >= 0) { if (existingRowIndex >= 0) {
targetsTable targetsTable
.row(existingRowIndex, {order: "index"}) .row(existingRowIndex, {
order: "index"
})
.data(newRow); .data(newRow);
} else { } else {
targetsTable.row.add(newRow); targetsTable.row.add(newRow);
} }
targetsTable.draw();
} }
function load() { function load() {
@ -194,14 +197,15 @@ function load() {
$(document).ready(function() { $(document).ready(function() {
load() load()
// Setup the event listeners // Setup the event listeners
// Handle manual additions // Handle manual additions
$("#targetForm").submit(function() { $("#targetForm").submit(function() {
addTarget( addTarget(
$("#firstName").val(), $("#firstName").val(),
$("#lastName").val(), $("#lastName").val(),
$("#email").val(), $("#email").val(),
$("#position").val()); $("#position").val());
targets.DataTable().draw();
// Reset user input. // Reset user input.
$("#targetForm>div>input").val(''); $("#targetForm>div>input").val('');