@@ -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,47 @@ 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 options = [ 10 , 25 , 50 , "all" ] ;
178+ options . forEach ( limit => {
179+ if ( rows . length >= limit || limit === "all" ) {
180+ const option = document . createElement ( 'option' ) ;
181+ option . value = limit ;
182+ option . textContent = limit === "all" ? "All" : limit ;
183+ option . selected = limit === "all" ? ( selected_option === "all" ) : ( limit === parseInt ( selected_option , 10 ) ) ;
184+ paginationLimitSelector . appendChild ( option ) ;
185+ }
186+ } ) ;
187+
188+ paginationLimitSelector . addEventListener ( 'change' , ( event ) => {
189+ const selectedValue = event . target . value ;
190+ const newLimit = selectedValue === "all" ? rows . length : parseInt ( selectedValue , 10 ) ;
191+ if ( gridInstance ) {
192+ gridInstance . updateConfig ( {
193+ pagination : {
194+ limit : newLimit
195+ }
196+ } ) . forceRender ( ) ;
197+ applyCustomFunctions ( gridInstance , tableId , headers , rows , selectedValue ) ;
198+ }
199+ } ) ;
200+
201+ paginationLimitDiv . appendChild ( document . createTextNode ( 'Show' ) ) ;
202+ paginationLimitDiv . appendChild ( paginationLimitSelector ) ;
203+ paginationLimitDiv . appendChild ( document . createTextNode ( 'rows' ) ) ;
204+
205+ const gridJSHeadDiv = document . querySelector ( `#gridjs-wrapper-${ tableId } .gridjs-head` ) ;
206+ if ( gridJSHeadDiv ) {
207+ gridJSHeadDiv . appendChild ( paginationLimitDiv ) ;
208+ }
209+ }
210+
170211function addGridJSWrapperScrollListener ( ) {
171212 document . querySelectorAll ( '.gridjs-wrapper' ) . forEach ( wrapper => {
172213 wrapper . addEventListener ( 'scroll' , ( ) => {
@@ -179,17 +220,25 @@ function addGridJSWrapperScrollListener() {
179220 } ) ;
180221}
181222
223+ function applyCustomFunctions ( gridInstance , tableId , headers , rows , selected_option = 10 ) {
224+ setTimeout ( ( ) => {
225+ addPaginationLimitSelector ( gridInstance , tableId , headers , rows , selected_option ) ;
226+ addDownloadButtons ( tableId , headers , rows ) ;
227+ addGridJSWrapperScrollListener ( ) ;
228+ } , 100 ) ;
229+ }
230+
182231async function initializeGridJS ( ) {
183232 await loadGridJSandJSPDF ( ) ;
184233
185234 const languageSettings = {
186235 search : {
187- 'placeholder' : '🔍 Search...'
236+ 'placeholder' : 'Search...'
188237 } ,
189238 pagination : {
190- previous : '⬅️ Previous ' ,
191- next : '➡️ Next' ,
192- showing : '📺 Displaying' ,
239+ previous : 'Prev ' ,
240+ next : 'Next' ,
241+ showing : 'Displaying' ,
193242 results : 'rows'
194243 } ,
195244 loading : 'Loading...' ,
@@ -243,13 +292,9 @@ async function initializeGridJS() {
243292
244293 gridInstance . render ( wrapper ) ;
245294
246- setTimeout ( ( ) => {
247- addDownloadButtons ( tableId , headers , rows ) ;
248- addGridJSWrapperScrollListener ( ) ;
249- } , 100 ) ;
250-
251- // Remove the original table
252- table . remove ( ) ;
295+ applyCustomFunctions ( gridInstance , tableId , headers , rows ) ;
296+ // Hide the original table
297+ table . style . display = 'none' ;
253298 } ) ;
254299}
255300
0 commit comments