I would like to display a simple table where (a) each column has, in its header cell, a little up-down arrow so that the user can sort the table on that column, and (b) a column where each row has a button “Delete This Row”, such that pushing the button (duh) deletes the row.
(a) I don’t see any built-in list element that has sortable columns. TableMaster makes tables with sortable columns, but I don’t see how to connect such a table to a collection. It seems that I need a built-in element (so I can connect to the collection) with a button that I create above each column to sort the collection (not the table) on that column. Or maybe I’ll have to have two buttons, one for each sort direction. Is there a simpler way to proceed?
(b) I have no idea what the basic approach is here. Looking for a pointer.
All help appreciated. Thanks.
You need to use a Repeater for this and do the coding for sorting and displaying a button per row yourself. There is no out-of-the-box solution for it (but coding it is also not too difficult). Try, and if you get stuck, show code and we will help.
Thanks very much. Following up on the sorting piece: Rather than a series of buttons, I’d prefer a dropdown: “Sort by…” where the dropdown choices are “Name”, “Date”, and so forth. Is there a way to connect dropdown selection with some sort of hook or callback code, so I can execute the sort? I could probably connect the dropdown to a collection and put a hook or something on the collection to execute the sort. But that seems super-clumsy. Any more direct way with a dropdown?
Later: Never mind. Found the appropriate handlers. I’ll give it a try.
Many thanks for your help. I now have everything working, with one exception.
I couldn’t find a repeater that looked like a table with header, so I left the table in place and put a very small repeater next to it, just the height of a table row, containing only a button. So the repeater puts buttons vertically, each adjacent to a row of the table. The repeater and table connect to the same dataset, so they’re tied together even if they’re technically independent.
The code for the repeater button just sets an “inactive” bit in the collection that backs both the repeaters and the table. Here’s the trouble: It works great in Preview but not at all in the live site. You click the button and the collection doesn’t change. I’m too much of a novice to understand why. This code appears on the Home Page’s code, in the front end. Am I not allowed to modify a table there, even if it works in Preview? If not, how do I do it?
Are you sure you synced Sandbox and Live collections? (happens to everyone)
I didn’t sync them—they have different data. But I shouldn’t have to. In the preview I see a list of the sandbox rows, with a delete button for each, and the delete buttons correctly delete (actually inactivate) the corresponding row from the sandbox collection. On the live site I see a different list of rows, the rows from the live site collection, each with a delete button, but the delete buttons do not work. Does syncing sync anything other than the rows of the collection?
Update: The new problem is definitely due to collection permissions. The
update statement, in code on the Home Page, gets an error saying that
the current user does not have permission to update the collection. This
is despite the fact that I’m using the “options” parameter to suppress
authorization checks. This error is not thrown in Preview. How do I set the permissions for the collection so that I can both see it and update it on the live site?
Answer: I found the interface for customizing collection permissions. It’s all solved.
Great. Now, if other people hit onto this thread, they wonder " so what was the solution?" It would be appreciated if you shared it here, so others can learn from your experience.
Suppose you have a table that’s to be both read and written on the live site. (In my case, it’s a table that’s displayed to the user, with delete buttons per row. Also, rows get added by POSTs sent from elsewhere.) When you create a new collection there’s a question “What’s the collection for?” If you answer “Site Content” then arbitrary users can see it, but not write it. If you answer “Form Submission” then arbitrary users can write it but not read it. You have to scroll down and select “Custom Use”. Nothing seems to happen, but a new button “Set Custom Permissions” appears at the bottom; click it, and you can set permissions at fine granularity any time you want.
The thing that confused me was this: My collection gets modified (rows added and fields updated) only in code , based on incoming POST requests and user clicks. You’re supposed to be able to override permissions by using certain options of the data collection update API. I had set the collection to “Site Content” and was using the override options in order to add rows (since you normally can’t write a “Site Content” collection). This worked perfectly. But updating existing rows failed because of permission problems even though I was using the permission override option. I still don’t know why that was. But of course setting the collection to be both read/write (which you can only do by setting custom permissions as above) solved the problem.
Thanks for your write-up, Larry. Closing this post.