Carl Booth Posted August 11, 2022 Share Posted August 11, 2022 (edited) Hi I can anyone help me with manipulating ProFields Table rows? It works ok using first() and last() as per the README, however I can't seem to manipulate specific items, given a selector. I presume I'm doing something wrong when selecting the row(s). $tt = $pages->findOne("template=repeater_basetimetables,title=Silver") // Works - from README $page->of(false); $opday = $page->operatingcalendar_days->last(); $opday->timetable = $tt; $page->save('operatingcalendar_days'); // Doesn't work - set to TableRows is not an allowed type $page->of(false); $opday = $page->operatingcalendar_days("ttdate=2022-08-11"); $opday->timetable = $tt; $page->save('operatingcalendar_days'); // Doesn't work - no error $page->of(false); $opday = $page->operatingcalendar_days("ttdate=2022-08-11")->first(); $opday->timetable = $tt; $page->save('operatingcalendar_days'); Or, do I have to remove and re-create rows I want to modify? Cheers Edited August 12, 2022 by Carl Booth changed code listing 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted August 11, 2022 Share Posted August 11, 2022 Hi Carl, welcome to the PW forums! Sorry, it’s not clear to me what $award and $tt are in your code? Also, it looks like you’re getting a table row into $opday and then never do anything with it? But yeah, modifying a specific item is described in the module’s readme: $page->of(false); // turn off output formatting, if necessary $award = $page->awards->first(); $award->title = "Most Sustainable Building"; $award->date = "2014-05-01"; $page->save('awards'); (I only have an exceedingly old version, your readme may differ.) Btw, there is a dedicated support board for ProFields, if you have access (I don’t). 1 Link to comment Share on other sites More sharing options...
Carl Booth Posted August 12, 2022 Author Share Posted August 12, 2022 Hi Jan Thanks for the welcome. $award->timetable is an artefact of me copy and pasting wrong, it should be $opday->timetable, which is a Page reference field in the table. $tt is a Page, the comment at the end that explains how I've assigned it ($pages->findOne). However I'm having the same problem if the field is a plain text. Your example (from the README) works correctly for me (it's essentially the first block in my code) however that's only the first() or last()) item - I'm needing to edit a specific filtered row (or set of rows) - those with a specific field value. I think this is what I'm struggling with - capturing those rows and editing them in a way the module will write back to the database table. Cheers 1 Link to comment Share on other sites More sharing options...
RyanJ Posted 5 hours ago Share Posted 5 hours ago This is an old thread, but I have searched hours for an answer to the same question. I am really surprised I could not find something about this, so I will post how I achieved this. I want to update a specific row in for my pro table field. So in my case, I have added the row id as a hidden input foreach ( $page->getUnformatted('my_table_field') as $item ) { $item->id; //get the id of the row to use in hidden input; } //update part $page->of(false); $update_row = $page->my_table_field->get("id=$id"); $update_row->title = $title; $update_row->description = $description; $page->save('my_table_field'); $page->of(true); I am curious if anyone sees any issues with this approach for if there is a better way doing so. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now