From cfa33d211372d40edcd35d2c0d74daf261fe6bf3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 11 Mar 2025 16:50:04 -0500 Subject: Extract common DataTables into a reusable function. --- uploader/static/js/species.js | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'uploader/static/js/species.js') diff --git a/uploader/static/js/species.js b/uploader/static/js/species.js index 1f2aa3b..c1374c6 100644 --- a/uploader/static/js/species.js +++ b/uploader/static/js/species.js @@ -1,19 +1,10 @@ -var speciesDataTable = (speciesdata) => { - var lengthMenu = [10, 25, 50, 100, 1000]; - if(speciesdata.length > 1000) { - lengthMenu.push(speciesdata.length) - } - $("#tbl-select-species").DataTable({ - responsive: true, - lengthMenu: lengthMenu, - language: { - processing: "Processing… Please wait.", - loadingRecords: "Loading species — Please wait.", - lengthMenu: "Show _MENU_ species", - info: "Showing _START_ to _END_ of _TOTAL_ species" - }, - data: speciesdata, - columns: [ +$(() => { + dtAddCommonHandlers("#tbl-select-species"); + var speciesDataTable = buildDataTable( + "#tbl-select-species", + JSON.parse( + $("#tbl-select-species").attr("data-species-list")), + [ { data: (aspecies) => { return ` { return `${aspecies.FullName} (${aspecies.SpeciesName})`; } } - ] - }); -}; - -$(() => { - dtAddCommonHandlers("#tbl-select-species"); - speciesDataTable(JSON.parse( - $("#tbl-select-species").attr("data-species-list"))); + ]); }); -- cgit 1.4.1