We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using "orderby" and "sort" for Grid field in Channel Form

How Do I?

IC360 (Oliver Cannell)'s avatar
IC360 (Oliver Cannell)
241 posts
9 years ago
IC360 (Oliver Cannell)'s avatar IC360 (Oliver Cannell)

I’m trying to do the following in a Channel Form, but the Grid doesn’t display on screen:

{field:client-notes orderby="date" sort="asc"}

Is this not possible?

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
9 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

Possible, however on a grid field the orderby is used with a column name. Here’re the docs Grid

       
IC360 (Oliver Cannell)'s avatar
IC360 (Oliver Cannell)
241 posts
9 years ago
IC360 (Oliver Cannell)'s avatar IC360 (Oliver Cannell)

Yes, my Grid column name is ‘date’ but orderby=”date” doesn’t seem to work.

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
9 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

I’ve tested this out on 3.3.0 and it’s working fine for me. Is your date column a date field type?

       
IC360 (Oliver Cannell)'s avatar
IC360 (Oliver Cannell)
241 posts
9 years ago
IC360 (Oliver Cannell)'s avatar IC360 (Oliver Cannell)

Thanks for investigating. Yes, the Date column is a Date fieldtype. I’m using EE 2.11.1

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

A grid field when publishing displays based on row order, which is controlled by the content author. Custom ordering isn’t available within the context of the Channel Form, as that would contradict the order set by the content author. @Pedro are you using within a channel form with the {field:... tag? Or just confirming that ordering by a Grid column works in a Channel Entries tag?

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
9 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

Correct, my test wasn’t with a channel form.

       
IC360 (Oliver Cannell)'s avatar
IC360 (Oliver Cannell)
241 posts
9 years ago
IC360 (Oliver Cannell)'s avatar IC360 (Oliver Cannell)

Yes I guess that makes sense, in terms of what the Grid was designed for, when being used in either the Control Panel or a Channel Form.

I’m using the Grid in a Channel Form, so that the user can enter notes about a client (while on the phone for example). Ideally I was hoping to output previous notes in order of the Date column, with latest first, and then allow them to add another note at the top.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

I suppose it depends on whether or not the content author needs to create and/or edit multiple rows at once, but if not, you could accomplish the above if instead of a Grid field, you had a Notes Channel that was reverse related to the Clients Channel. While on the phone they could view a page for the client that had all of the existing data however it needs to be displayed, and an entry form for the Notes Channel for a new note. The relationship field could be hidden and you could set the value based on the Client Channel Entry being viewed.

       
IC360 (Oliver Cannell)'s avatar
IC360 (Oliver Cannell)
241 posts
9 years ago
IC360 (Oliver Cannell)'s avatar IC360 (Oliver Cannell)

Yes that might be a more flexible option - although it will mean having a lot of Note entries on the database. I’m guessing this wont be a problem though. How do I auto assign (relate) a new Notes Entry to the currently displayed Client Entry in a Channel Form?

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

No, no worries there. You do shift them to a different table by being in a Grid, but you gain flexibility. Are you anticipating hundreds of thousands, or even millions of notes?

You’d need to send a hidden field for the relationship’s field ID, populated with the entry ID of the Client entry. If that doesn’t click, go ahead and output the relationship form field in the context you are looking for, and inspect the HTML to see the form field name and expected values.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.