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/populations.js | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'uploader/static/js/populations.js') diff --git a/uploader/static/js/populations.js b/uploader/static/js/populations.js index 5c1f848..73e298a 100644 --- a/uploader/static/js/populations.js +++ b/uploader/static/js/populations.js @@ -1,19 +1,10 @@ -var populationDataTable = (populationdata) => { - var lengthMenu = [10, 25, 50, 100, 1000]; - if(populationdata.length > 1000) { - lengthMenu.push(populationdata.length) - } - $("#tbl-select-population").DataTable({ - responsive: true, - lengthMenu: lengthMenu, - language: { - processing: "Processing… Please wait.", - loadingRecords: "Loading population — Please wait.", - lengthMenu: "Show _MENU_ populations", - info: "Showing _START_ to _END_ of _TOTAL_ populations" - }, - data: populationdata, - columns: [ +$(() => { + dtAddCommonHandlers("#tbl-select-population"); + var populationsDataTable = buildDataTable( + "#tbl-select-population", + JSON.parse( + $("#tbl-select-population").attr("data-populations-list")), + [ { data: (apopulation) => { return ` { return `${apopulation.FullName} (${apopulation.InbredSetName})`; } } - ] - }); -}; - - -$(() => { - dtAddCommonHandlers("#tbl-select-population"); - populationDataTable(JSON.parse( - $("#tbl-select-population").attr("data-populations-list"))); + ]); }); -- cgit v1.2.3