try pagination templ

This commit is contained in:
Sas Andy
2024-05-08 13:28:03 +07:00
parent 8f2104270d
commit ad26d88feb
12 changed files with 554 additions and 42 deletions

View File

@@ -2,10 +2,13 @@ package handlers
import (
"fmt"
"strconv"
"github.com/a-h/templ"
"github.com/emarifer/go-templ-project-structure/models"
"github.com/emarifer/go-templ-project-structure/services"
"github.com/emarifer/go-templ-project-structure/views/component/pagination"
tablecomponent "github.com/emarifer/go-templ-project-structure/views/component/table"
mastermenuusergroup "github.com/emarifer/go-templ-project-structure/views/mastermenuusergroup"
"github.com/labstack/echo/v4"
)
@@ -74,6 +77,29 @@ func (lh *MasterMenuUserGroupHandler) ChangeFormEdit(c echo.Context) error {
return lh.View(c, vw)
}
func (lh *MasterMenuUserGroupHandler) HandleChangePage(c echo.Context) error {
page := c.QueryParam("page")
currPage := c.QueryParam("currentPage")
dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroup()
if err != nil {
fmt.Println(dataUserGroup)
return err
}
pageInt, err := strconv.Atoi(page)
if err != nil {
fmt.Println("page err")
return err
}
currPageInt, err := strconv.Atoi(currPage)
if err != nil {
fmt.Println("currpage err")
return err
}
vw := tablecomponent.Table([]string{"KODE", "USERGROUP", "AKSI"}, []string{"40%", "40%", "20%"}, mastermenuusergroup.TableRow(dataUserGroup), pagination.Pagination(pageInt, currPageInt))
return lh.View(c, vw)
}
func (uh *MasterMenuUserGroupHandler) View(c echo.Context, cmp templ.Component) error {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)

View File

@@ -30,6 +30,7 @@ func SetupRoutesLandingPage(app *echo.Echo, h *LandingPageHandler, mastermenuuse
// clientusergroup.GET("/md", mastermenuusergroupHandler.HandlerShowMasterMenuUserGroup)
clientgroup.GET("/usergroup", mastermenuusergroupHandler.HandlerShowMasterMenuUserGroup)
clientgroup.GET("/usergroup/edit", mastermenuusergroupHandler.ChangeFormEdit)
clientgroup.GET("/usergroup/pagination", mastermenuusergroupHandler.HandleChangePage)
}
func SetupRoutesPieChart(app *echo.Echo, h *PiechartHandler) {