package bulkupdate import ( "fmt" "examples/shared" ) templ demo(users []user) {

Select Rows And Activate Or Deactivate Below

@tbody(users, map[int]bool{})
Name Email Status
Activate
Deactivate
} templ tbody(users []user, modified map[int]bool) { for k, u := range users { { u.name } { u.email } if u.active { Active } else { Inactive } } } templ Index(users []user) { @shared.Layout("Bulk Update") {

Bulk Update

This demo shows how to implement a common pattern where rows are selected and then bulk updated. This is accomplished by putting a form around a table, with checkboxes in the table, and then including the checked values in PUT’s to two different endpoints: activateand deactivate:


	@shared.Raw() {
		@demo(users)
	}

The server will either activate or deactivate the checked users and then rerender the tbodytag with updated rows. It will apply the class activateor deactivateto rows that have been mutated. This allows us to use a bit of CSS to flash a color helping the user see what happened:

{ `.htmx-settling tr.deactivate td { 
    background: lightcoral;
} 
.htmx-settling tr.activate td { 
    background: darkseagreen;
}
tr td { 
    transition: all 1.2s;
}` }

Demo

@demo(users) } }