Skip to content

Anchor links in tables do not work with true as search #542

Closed
@lovasoa

Description

@lovasoa

When a table has true as search, loading the page with a specific anchor fails.

Minimal repro:

index.sql

select 'button' as component;
select 'scroll to 256' as title, 'scroll.sql' as link;

SELECT 'table' AS component, true as search;
with recursive numbers(n) as (
    select 1 union all select n + 1 from numbers where n < 500
)
SELECT n, n as _sqlpage_id FROM numbers;

scroll.sql

select 'redirect' as component, '/x.sql#256' as link;

Discussed in #538

Originally posted by lozdown August 15, 2024

Background

I populate a table component with rows from a database. Each row is identified using unique column id. Using markdown a column in each row provides a link to another sqlpage page with id as a parameter. This second page updates the database and returns back to the table. I want to return to the row used in the call identified by id. I intended to use an html anchor but I can't make it work.

There seems to be two problems

  1. the example url http://127.0.0.1:8080/member-event.sql#id441963 does not move to the requested row in the table created by member-event.sql
  2. the returning redirect component does not create the correct url

Table component definition (cut down) from member-event.sql

 select 
 	'table' as 'component', true as 'small',true as striped_columns,
 	TRUE as search,
 	'2024-01-17' as markdown
 	;
 
select m."First Name",m."Last Name",
 	case when "2024-01-17"  
 		then 
 			format('[](#%s)[&#x2713;](remove-member-event.sql?memberid=%s&eventid=%s)', a.contactid,a.contactid,(select distinct id from eventinfo where eventdate='2024-01-17') ) 
		else 
 			format('[](#%s)[x](update-member-event.sql?memberid=%s&eventid=%s)', a.contactid,a.contactid,(select distinct id from eventinfo where eventdate='2024-01-17') )  
		end as "2024-01-17" 
 	from members m left join attendances a on m."Contact ID"=a.contactid
;
 

The update-member-event.sql file definition is

INSERT INTO public.events_members(
	events_id, "members_Contact ID")
	VALUES ($eventid::int, $memberid::int)
RETURNING
    'redirect' AS component,
    'member-event.sql#$memberid' AS link
;

I was expecting the redirect to return a url something like member-event.sql#441963 but it actually returns verbatim (ie with no substitution of the parameter value) member-event.sql#$memberid

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions