@@ -142,8 +142,8 @@ function addDownloadButtons(tableId, headers, rows) {
142142
143143 csvDownloadBtns . id = `${ tableId } -download-csv` ;
144144 pdfDownloadBtns . id = `${ tableId } -download-pdf` ;
145- csvDownloadBtns . textContent = "Download CSV" ;
146- pdfDownloadBtns . textContent = "Download PDF" ;
145+ csvDownloadBtns . textContent = "CSV" ;
146+ pdfDownloadBtns . textContent = "PDF" ;
147147 downloadBtns . appendChild ( csvDownloadBtns ) ;
148148 downloadBtns . appendChild ( pdfDownloadBtns ) ;
149149 downloadBtns . id = `${ tableId } -download-btns` ;
@@ -167,6 +167,49 @@ function addDownloadButtons(tableId, headers, rows) {
167167 }
168168}
169169
170+ function addPaginationLimitSelector ( gridInstance , tableId , headers , rows , selected_option = 10 ) {
171+ const paginationLimitDiv = document . createElement ( 'div' ) ;
172+ paginationLimitDiv . className = 'gridjs-pagination-limit-div' ;
173+ const paginationLimitSelector = document . createElement ( 'select' ) ;
174+ paginationLimitSelector . id = `${ tableId } -pagination-limit` ;
175+ paginationLimitSelector . className = 'gridjs-pagination-limit' ;
176+
177+ const option_selected = selected_option ;
178+
179+ const options = [ 10 , 25 , 50 , "all" ] ;
180+ options . forEach ( limit => {
181+ if ( rows . length >= limit || limit === "all" ) {
182+ const option = document . createElement ( 'option' ) ;
183+ option . value = limit ;
184+ option . textContent = limit === "all" ? "All" : limit ;
185+ option . selected = ( limit === option_selected ) ;
186+ paginationLimitSelector . appendChild ( option ) ;
187+ }
188+ } ) ;
189+
190+ paginationLimitSelector . addEventListener ( 'change' , ( event ) => {
191+ const selectedValue = event . target . value ;
192+ const newLimit = selectedValue === "all" ? rows . length : parseInt ( selectedValue , 10 ) ;
193+ if ( gridInstance ) {
194+ gridInstance . updateConfig ( {
195+ pagination : {
196+ limit : newLimit
197+ }
198+ } ) . forceRender ( ) ;
199+ applyCustomFunctions ( gridInstance , tableId , headers , rows , selectedValue ) ;
200+ }
201+ } ) ;
202+
203+ paginationLimitDiv . appendChild ( document . createTextNode ( 'Show' ) ) ;
204+ paginationLimitDiv . appendChild ( paginationLimitSelector ) ;
205+ paginationLimitDiv . appendChild ( document . createTextNode ( 'rows' ) ) ;
206+
207+ const gridJSHeadDiv = document . querySelector ( `#gridjs-wrapper-${ tableId } .gridjs-head` ) ;
208+ if ( gridJSHeadDiv ) {
209+ gridJSHeadDiv . appendChild ( paginationLimitDiv ) ;
210+ }
211+ }
212+
170213function addGridJSWrapperScrollListener ( ) {
171214 document . querySelectorAll ( '.gridjs-wrapper' ) . forEach ( wrapper => {
172215 wrapper . addEventListener ( 'scroll' , ( ) => {
@@ -179,17 +222,25 @@ function addGridJSWrapperScrollListener() {
179222 } ) ;
180223}
181224
225+ function applyCustomFunctions ( gridInstance , tableId , headers , rows , selected_option = 10 ) {
226+ setTimeout ( ( ) => {
227+ addPaginationLimitSelector ( gridInstance , tableId , headers , rows , selected_option ) ;
228+ addDownloadButtons ( tableId , headers , rows ) ;
229+ addGridJSWrapperScrollListener ( ) ;
230+ } , 100 ) ;
231+ }
232+
182233async function initializeGridJS ( ) {
183234 await loadGridJSandJSPDF ( ) ;
184235
185236 const languageSettings = {
186237 search : {
187- 'placeholder' : '🔍 Search...'
238+ 'placeholder' : 'Search...'
188239 } ,
189240 pagination : {
190- previous : '⬅️ Previous ' ,
191- next : '➡️ Next' ,
192- showing : '📺 Displaying' ,
241+ previous : 'Prev ' ,
242+ next : 'Next' ,
243+ showing : 'Displaying' ,
193244 results : 'rows'
194245 } ,
195246 loading : 'Loading...' ,
@@ -243,13 +294,9 @@ async function initializeGridJS() {
243294
244295 gridInstance . render ( wrapper ) ;
245296
246- setTimeout ( ( ) => {
247- addDownloadButtons ( tableId , headers , rows ) ;
248- addGridJSWrapperScrollListener ( ) ;
249- } , 100 ) ;
250-
251- // Remove the original table
252- table . remove ( ) ;
297+ applyCustomFunctions ( gridInstance , tableId , headers , rows ) ;
298+ // Hide the original table
299+ table . style . display = 'none' ;
253300 } ) ;
254301}
255302
0 commit comments