diff --git a/docs/docsrc/examples/examples_presets/listing.go b/docs/docsrc/examples/examples_presets/listing.go index 70b91a0f0..5c5b8fcca 100644 --- a/docs/docsrc/examples/examples_presets/listing.go +++ b/docs/docsrc/examples/examples_presets/listing.go @@ -97,7 +97,17 @@ func PresetsListingCustomizationFields(b *presets.Builder, db *gorm.DB) ( mb, cl, ce, dp = PresetsHelloWorld(b, db) cl = mb.Listing("ID", "Name", "Company", "Email"). - SearchColumns("name", "email").SelectableColumns(true) + SearchColumns("name", "email").SelectableColumns(true). + OrderableFields([]*presets.OrderableField{ + { + FieldName: "ID", + DBColumn: "id", + }, + { + FieldName: "Name", + DBColumn: "name", + }, + }) cl.Field("Company").ComponentFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent { c := obj.(*Customer) var comp Company diff --git a/go.mod b/go.mod index 943c62416..4c2f76b46 100644 --- a/go.mod +++ b/go.mod @@ -26,13 +26,13 @@ require ( github.com/pkg/errors v0.9.1 github.com/pquerna/otp v1.4.0 github.com/qor/oss v0.0.0-20230717083721-c04686f83630 - github.com/qor5/web/v3 v3.0.5-0.20240717040023-4b80a69c031d + github.com/qor5/web/v3 v3.0.5-0.20240723094007-d24081129126 github.com/qor5/x/v3 v3.0.6-0.20240723060143-cae2d56f60a2 github.com/samber/lo v1.46.0 github.com/shurcooL/sanitized_anchor_name v1.0.0 github.com/spf13/cast v1.6.0 github.com/stretchr/testify v1.9.0 - github.com/sunfmin/reflectutils v1.0.5 + github.com/sunfmin/reflectutils v1.0.6-0.20240723093451-ac287aca03a9 github.com/sunfmin/snippetgo v0.0.3 github.com/theplant/bimg v1.1.1 github.com/theplant/docgo v0.0.16 diff --git a/go.sum b/go.sum index 8e0fae4cc..f4b927316 100644 --- a/go.sum +++ b/go.sum @@ -317,12 +317,8 @@ github.com/qor/oss v0.0.0-20230717083721-c04686f83630 h1:CRi4xF7B8aGX/y48NCjarNd github.com/qor/oss v0.0.0-20230717083721-c04686f83630/go.mod h1:FDxJAVwmZ1j8ITcKJExFlzkTYuUor1dBKZgNVWqEqlM= github.com/qor5/web v1.3.2 h1:zw796YJeDLe8vRwGR1cM+uS1ZuSkPutchBEXv2GgOhI= github.com/qor5/web v1.3.2/go.mod h1:LszskQJbFQDJwOeZC6j6afOiHxxyjrzz8B3zuBwfgKQ= -github.com/qor5/web/v3 v3.0.5-0.20240717040023-4b80a69c031d h1:IKW0l0FZAmczHynvBOH6MQjfqpL5v9pSf094uO7U9io= -github.com/qor5/web/v3 v3.0.5-0.20240717040023-4b80a69c031d/go.mod h1:RPLKS/poCC6yN+CKPQB1iS7g2V0iz7vIsJSY6v/8zY0= -github.com/qor5/x/v3 v3.0.6-0.20240716033136-45995deaaeb2 h1:+PKEd+OBDnJj6OVz4I+GubbiUmzMXsOiR/tOk7paidY= -github.com/qor5/x/v3 v3.0.6-0.20240716033136-45995deaaeb2/go.mod h1:85rLAySzyq7L0dWXzICMnBVULCv53AtYmx3x1qeCDx0= -github.com/qor5/x/v3 v3.0.6-0.20240723021616-8a45a777a11c h1:u4M7e7HWl/t3HQPuj3zOp/PuAxqOn9o0ejOMHfeQvwQ= -github.com/qor5/x/v3 v3.0.6-0.20240723021616-8a45a777a11c/go.mod h1:85rLAySzyq7L0dWXzICMnBVULCv53AtYmx3x1qeCDx0= +github.com/qor5/web/v3 v3.0.5-0.20240723094007-d24081129126 h1:LfWbM+CBJbgDqKDyRk8GeYYOoZ8UgQG17t5DwoYUX9o= +github.com/qor5/web/v3 v3.0.5-0.20240723094007-d24081129126/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0= github.com/qor5/x/v3 v3.0.6-0.20240723060143-cae2d56f60a2 h1:Ed4WRJS9uNomilDEgd6MA/YqrdeGu/0rl2q627hkXmA= github.com/qor5/x/v3 v3.0.6-0.20240723060143-cae2d56f60a2/go.mod h1:85rLAySzyq7L0dWXzICMnBVULCv53AtYmx3x1qeCDx0= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= @@ -379,8 +375,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/sunfmin/reflectutils v1.0.5 h1:izu+W1FasRz0KXUqFo/h4GKsXveDiUt3SwVvFs6w0wU= -github.com/sunfmin/reflectutils v1.0.5/go.mod h1:ao2bbF4RZrTe2PboJKdZoC3BA71gdU6rFkCuUjoeqMw= +github.com/sunfmin/reflectutils v1.0.6-0.20240723093451-ac287aca03a9 h1:uGwnYgklZ5WLaQO8GKg4vGP2kykhrQztoAZ5/huKnG0= +github.com/sunfmin/reflectutils v1.0.6-0.20240723093451-ac287aca03a9/go.mod h1:ao2bbF4RZrTe2PboJKdZoC3BA71gdU6rFkCuUjoeqMw= github.com/sunfmin/snippetgo v0.0.3 h1:pMCpFCyW2fYHhfLp4tb5ccvTCpIuSNFomtDCr9duUaE= github.com/sunfmin/snippetgo v0.0.3/go.mod h1:Ue+VuRdcJfuRkdxawPJOYYqKw1MgeJNwAz1qCc1pazQ= github.com/testcontainers/testcontainers-go v0.31.0 h1:W0VwIhcEVhRflwL9as3dhY6jXjVCA27AkmbnZ+UTh3U= diff --git a/presets/listing_compo.go b/presets/listing_compo.go index bcffb1777..3f9dade64 100644 --- a/presets/listing_compo.go +++ b/presets/listing_compo.go @@ -158,6 +158,7 @@ func (c *ListingCompo) tabsFilter(ctx context.Context) h.HTMLComponent { tabs.AppendChildren( VTab(). Attr("@click", stateful.ReloadAction(ctx, c, func(target *ListingCompo) { + target.Page = 0 target.ActiveFilterTab = ft.ID target.FilterQuery = encodedQuery }).Go()). @@ -182,7 +183,10 @@ func (c *ListingCompo) textFieldSearch(ctx context.Context) h.HTMLComponent { return nil } _, msgr := c.MustGetEventContext(ctx) - reloadAction := stateful.ReloadAction(ctx, c, nil, + reloadAction := stateful.ReloadAction(ctx, c, + func(target *ListingCompo) { + target.Page = 0 + }, stateful.WithAppendFix(`v.compo.keyword = xlocals.keyword`), ).Go() return web.Scope().VSlot("{ locals: xlocals }").Init(fmt.Sprintf("{ keyword: %q }", c.Keyword)).Children( @@ -199,6 +203,7 @@ func (c *ListingCompo) textFieldSearch(ctx context.Context) h.HTMLComponent { Attr("v-model", "xlocals.keyword"). Attr("@keyup.enter", reloadAction). Attr("@click:clear", stateful.ReloadAction(ctx, c, func(target *ListingCompo) { + target.Page = 0 target.Keyword = "" }).Go()). Children( @@ -287,7 +292,9 @@ func (c *ListingCompo) filterSearch(ctx context.Context, fd vx.FilterData) h.HTM }`)) return web.Scope().VSlot("{locals:xlocals}").Init("{textFieldSearchElem: null}").Children( vx.VXFilter(fd).Translations(ft). - UpdateModelValue(stateful.ReloadAction(ctx, c, nil, opts...).Go()). + UpdateModelValue(stateful.ReloadAction(ctx, c, func(target *ListingCompo) { + target.Page = 0 + }, opts...).Go()). Attr("v-run", fmt.Sprintf(`(el) => { xlocals.textFieldSearchElem = el.ownerDocument.getElementById(%q); }`, c.textFieldSearchID())), @@ -440,6 +447,7 @@ func (c *ListingCompo) dataTable(ctx context.Context) h.HTMLComponent { } return h.Th("").Style("cursor: pointer; white-space: nowrap;"). Attr("@click.stop", stateful.ReloadAction(ctx, c, func(target *ListingCompo) { + target.Page = 0 if orderBy.OrderBy == OrderByASC { orderBy.OrderBy = OrderByDESC } else { @@ -513,7 +521,10 @@ func (c *ListingCompo) dataTable(ctx context.Context) h.HTMLComponent { PerPage(searchParams.PerPage). CustomPerPages([]int64{c.lb.perPage}). PerPageText(msgr.PaginationRowsPerPage). - OnSelectPerPage(stateful.ReloadAction(ctx, c, nil, + OnSelectPerPage(stateful.ReloadAction(ctx, c, + func(target *ListingCompo) { + target.Page = 0 + }, stateful.WithAppendFix(`v.compo.per_page = parseInt($event, 10)`), ).Go()). OnPrevPage(stateful.ReloadAction(ctx, c, func(target *ListingCompo) { diff --git a/utils/testflow/gentool/go.mod b/utils/testflow/gentool/go.mod index 205ab8f29..55534a581 100644 --- a/utils/testflow/gentool/go.mod +++ b/utils/testflow/gentool/go.mod @@ -6,7 +6,7 @@ require ( github.com/gobuffalo/flect v1.0.2 github.com/pkg/errors v0.9.1 github.com/qor5/admin/v3 v3.0.1-0.20240424102851-d75759576158 - github.com/qor5/web/v3 v3.0.5-0.20240717040023-4b80a69c031d + github.com/qor5/web/v3 v3.0.5-0.20240723094007-d24081129126 github.com/sergi/go-diff v1.3.1 mvdan.cc/gofumpt v0.6.0 ) diff --git a/utils/testflow/gentool/go.sum b/utils/testflow/gentool/go.sum index 4085a2aca..e642f07eb 100644 --- a/utils/testflow/gentool/go.sum +++ b/utils/testflow/gentool/go.sum @@ -20,8 +20,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/qor5/web/v3 v3.0.5-0.20240717040023-4b80a69c031d h1:IKW0l0FZAmczHynvBOH6MQjfqpL5v9pSf094uO7U9io= -github.com/qor5/web/v3 v3.0.5-0.20240717040023-4b80a69c031d/go.mod h1:RPLKS/poCC6yN+CKPQB1iS7g2V0iz7vIsJSY6v/8zY0= +github.com/qor5/web/v3 v3.0.5-0.20240723094007-d24081129126 h1:LfWbM+CBJbgDqKDyRk8GeYYOoZ8UgQG17t5DwoYUX9o= +github.com/qor5/web/v3 v3.0.5-0.20240723094007-d24081129126/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=