@@ -272,6 +272,111 @@ <h3>Expandable + Multi-select</h3>
272272 </ sgds-data-table >
273273</ div >
274274
275+ <!-- Custom footer text -->
276+ < div class ="container ">
277+ < h3 > Custom Footer Text (footerText)</ h3 >
278+ < sgds-data-table currentPage ="1 " dataLength ="4 " itemsPerPage ="2 " footerText ="Showing records fetched from API cache ">
279+ < sgds-data-table-row >
280+ < sgds-data-table-head > ID</ sgds-data-table-head >
281+ < sgds-data-table-head > Name</ sgds-data-table-head >
282+ </ sgds-data-table-row >
283+ < sgds-data-table-row >
284+ < sgds-data-table-cell > 1</ sgds-data-table-cell >
285+ < sgds-data-table-cell > Amy</ sgds-data-table-cell >
286+ </ sgds-data-table-row >
287+ < sgds-data-table-row >
288+ < sgds-data-table-cell > 2</ sgds-data-table-cell >
289+ < sgds-data-table-cell > Ben</ sgds-data-table-cell >
290+ </ sgds-data-table-row >
291+ < sgds-data-table-row >
292+ < sgds-data-table-cell > 3</ sgds-data-table-cell >
293+ < sgds-data-table-cell > Cara</ sgds-data-table-cell >
294+ </ sgds-data-table-row >
295+ < sgds-data-table-row >
296+ < sgds-data-table-cell > 4</ sgds-data-table-cell >
297+ < sgds-data-table-cell > Dan</ sgds-data-table-cell >
298+ </ sgds-data-table-row >
299+ </ sgds-data-table >
300+ </ div >
301+
302+ <!-- Hide footer -->
303+ < div class ="container ">
304+ < h3 > Hide Footer (hideFooter)</ h3 >
305+ < sgds-data-table currentPage ="1 " dataLength ="3 " itemsPerPage ="5 " hideFooter >
306+ < sgds-data-table-row >
307+ < sgds-data-table-head > ID</ sgds-data-table-head >
308+ < sgds-data-table-head > Status</ sgds-data-table-head >
309+ </ sgds-data-table-row >
310+ < sgds-data-table-row >
311+ < sgds-data-table-cell > 1001</ sgds-data-table-cell >
312+ < sgds-data-table-cell > Pending</ sgds-data-table-cell >
313+ </ sgds-data-table-row >
314+ < sgds-data-table-row >
315+ < sgds-data-table-cell > 1002</ sgds-data-table-cell >
316+ < sgds-data-table-cell > Approved</ sgds-data-table-cell >
317+ </ sgds-data-table-row >
318+ < sgds-data-table-row >
319+ < sgds-data-table-cell > 1003</ sgds-data-table-cell >
320+ < sgds-data-table-cell > Rejected</ sgds-data-table-cell >
321+ </ sgds-data-table-row >
322+ </ sgds-data-table >
323+ </ div >
324+
325+ <!-- Server mode -->
326+ < div class ="container ">
327+ < h3 > Server Mode (mode="server")</ h3 >
328+ < sgds-data-table id ="server-table " currentPage ="1 " dataLength ="50 " itemsPerPage ="10 " mode ="server " isLoading >
329+ < sgds-data-table-row >
330+ < sgds-data-table-head > ID</ sgds-data-table-head >
331+ < sgds-data-table-head > Name</ sgds-data-table-head >
332+ < sgds-data-table-head > Region</ sgds-data-table-head >
333+ </ sgds-data-table-row >
334+ </ sgds-data-table >
335+ </ div >
336+
337+ <!-- Header props: sortable, sortKey, width, colspan, rowspan, textAlign -->
338+ < div class ="container ">
339+ < h3 > Header Props (sortable, sortKey, width, colspan, rowspan, textAlign)</ h3 >
340+ < sgds-data-table currentPage ="1 " dataLength ="4 " itemsPerPage ="4 ">
341+ < sgds-data-table-row >
342+ < sgds-data-table-head rowspan ="2 " width ="88 "> ID</ sgds-data-table-head >
343+ < sgds-data-table-head colspan ="2 "> Profile</ sgds-data-table-head >
344+ < sgds-data-table-head rowspan ="2 " sortable sortKey ="score " width ="120 " textAlign ="right "
345+ > Score</ sgds-data-table-head
346+ >
347+ </ sgds-data-table-row >
348+ < sgds-data-table-row >
349+ < sgds-data-table-head sortable sortKey ="name "> Name</ sgds-data-table-head >
350+ < sgds-data-table-head sortable sortKey ="role "> Role</ sgds-data-table-head >
351+ </ sgds-data-table-row >
352+
353+ < sgds-data-table-row id ="sort-row-1 ">
354+ < sgds-data-table-cell > 1</ sgds-data-table-cell >
355+ < sgds-data-table-cell > Lina</ sgds-data-table-cell >
356+ < sgds-data-table-cell > Engineer</ sgds-data-table-cell >
357+ < sgds-data-table-cell > 82</ sgds-data-table-cell >
358+ </ sgds-data-table-row >
359+ < sgds-data-table-row id ="sort-row-2 ">
360+ < sgds-data-table-cell > 2</ sgds-data-table-cell >
361+ < sgds-data-table-cell > Adam</ sgds-data-table-cell >
362+ < sgds-data-table-cell > Designer</ sgds-data-table-cell >
363+ < sgds-data-table-cell > 90</ sgds-data-table-cell >
364+ </ sgds-data-table-row >
365+ < sgds-data-table-row id ="sort-row-3 ">
366+ < sgds-data-table-cell > 3</ sgds-data-table-cell >
367+ < sgds-data-table-cell > Nora</ sgds-data-table-cell >
368+ < sgds-data-table-cell > Manager</ sgds-data-table-cell >
369+ < sgds-data-table-cell > 75</ sgds-data-table-cell >
370+ </ sgds-data-table-row >
371+ < sgds-data-table-row id ="sort-row-4 ">
372+ < sgds-data-table-cell > 4</ sgds-data-table-cell >
373+ < sgds-data-table-cell > Ben</ sgds-data-table-cell >
374+ < sgds-data-table-cell > Engineer</ sgds-data-table-cell >
375+ < sgds-data-table-cell > 88</ sgds-data-table-cell >
376+ </ sgds-data-table-row >
377+ </ sgds-data-table >
378+ </ div >
379+
275380< script type ="module ">
276381 // Set rowData on multi-select rows
277382 document . getElementById ( "ms-row-1" ) . rowData = { id : 1 , name : "John Doe" } ;
@@ -282,4 +387,72 @@ <h3>Expandable + Multi-select</h3>
282387 document . getElementById ( "ems-row-1" ) . rowData = { id : 1 , name : "John Doe" } ;
283388 document . getElementById ( "ems-row-2" ) . rowData = { id : 2 , name : "Jane Doe" } ;
284389 document . getElementById ( "ems-row-3" ) . rowData = { id : 3 , name : "Bob Smith" } ;
390+
391+ // Set rowData for sortable table head demo (sortKey)
392+ document . getElementById ( "sort-row-1" ) . rowData = { id : 1 , name : "Lina" , role : "Engineer" , score : 82 } ;
393+ document . getElementById ( "sort-row-2" ) . rowData = { id : 2 , name : "Adam" , role : "Designer" , score : 90 } ;
394+ document . getElementById ( "sort-row-3" ) . rowData = { id : 3 , name : "Nora" , role : "Manager" , score : 75 } ;
395+ document . getElementById ( "sort-row-4" ) . rowData = { id : 4 , name : "Ben" , role : "Engineer" , score : 88 } ;
396+
397+ // Mock API-driven pagination demo for server mode table
398+ const serverTable = document . getElementById ( "server-table" ) ;
399+ const totalRows = 50 ;
400+ const regions = [ "North" , "South" , "East" , "West" , "Central" ] ;
401+
402+ const mockApi = ( { page, itemsPerPage } ) => {
403+ const start = ( page - 1 ) * itemsPerPage ;
404+ const end = Math . min ( start + itemsPerPage , totalRows ) ;
405+
406+ const rows = Array . from ( { length : Math . max ( 0 , end - start ) } , ( _ , index ) => {
407+ const id = start + index + 1 ;
408+ return {
409+ id,
410+ name : `Citizen ${ id } ` ,
411+ region : regions [ id % regions . length ]
412+ } ;
413+ } ) ;
414+
415+ return new Promise ( resolve => {
416+ setTimeout ( ( ) => {
417+ resolve ( { total : totalRows , rows } ) ;
418+ } , 350 ) ;
419+ } ) ;
420+ } ;
421+
422+ const renderServerRows = rows => {
423+ const headerRow = serverTable . querySelector ( "sgds-data-table-row" ) ;
424+ if ( ! headerRow ) return ;
425+
426+ const bodyMarkup = rows
427+ . map (
428+ row => `
429+ <sgds-data-table-row>
430+ <sgds-data-table-cell>${ row . id } </sgds-data-table-cell>
431+ <sgds-data-table-cell>${ row . name } </sgds-data-table-cell>
432+ <sgds-data-table-cell>${ row . region } </sgds-data-table-cell>
433+ </sgds-data-table-row>`
434+ )
435+ . join ( "" ) ;
436+
437+ serverTable . innerHTML = `${ headerRow . outerHTML } ${ bodyMarkup } ` ;
438+ } ;
439+
440+ const loadServerPage = async page => {
441+ const itemsPerPage = Number ( serverTable . itemsPerPage || 10 ) ;
442+ serverTable . isLoading = true ;
443+
444+ try {
445+ const response = await mockApi ( { page, itemsPerPage } ) ;
446+ serverTable . dataLength = response . total ;
447+ renderServerRows ( response . rows ) ;
448+ } finally {
449+ serverTable . isLoading = false ;
450+ }
451+ } ;
452+
453+ serverTable . addEventListener ( "sgds-page-change" , async ( ) => {
454+ await loadServerPage ( Number ( serverTable . currentPage || 1 ) ) ;
455+ } ) ;
456+
457+ loadServerPage ( 1 ) ;
285458</ script >
0 commit comments