Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This happens because grid column names must correspond to your fields or properties. Method which generates url in grid header compares "sort" from url query string with bounded columns and with grid column name. The three of them must be the same. If definition of your column name is not configured properly, the url will not be generated correctly.</p> <p>Anyway .. here is some examples of properly defined column names.</p> <p>Here we have sample domain class to display</p> <pre><code>public class Person { public string FirstName; public string LastName; public Address LivesIn; } public class Address { public string Country; public string City; } </code></pre> <p>Now lets display List</p> <p>Use your column names as fields</p> <pre><code>grid.Column("FirstName"), grid.Column("LastName"), grid.Column("LivesIn.City"), grid.Column("LivesIn.Country") </code></pre> <p>... all columns has correct sorting url</p> <p>If you make a typo in column name you got exception</p> <pre><code>grid.Column("FirstName"), grid.Column("MyLastName"), &lt;-- this throws exception grid.Column("LivesIn.City"), grid.Column("LivesIn.Country") </code></pre> <p>But you can use format and there will be no exception thrown</p> <pre><code>grid.Column("FirstName"), grid.Column("MyLastName", format: item =&gt; item.LastName&lt;/text&gt;), grid.Column("LivesIn.City"), grid.Column("LivesIn.Country") </code></pre> <p>... but sorting url for column MyLastName will be BAD !!! all the time sortDir=ASC</p> <p>You need to use good column name to has proper sorting url and custom format so ...</p> <pre><code>grid.Column("FirstName"), grid.Column("LastName", format: item =&gt; item.LastName), grid.Column("LivesIn.City"), grid.Column("LivesIn.Country") </code></pre> <p>... everything is ok</p> <p>How about complex type ? </p> <pre><code>grid.Column("FirstName"), grid.Column("LastName"), grid.Column("LivesIn.MyNonExistingField", format: item =&gt; item.LivesIn.City), grid.Column("LivesIn.Country") </code></pre> <p>.... wow ... everything is ok .. that's kid of bug .. column "LivesIn.MyNonExistingField" has proper sorting url.</p> <p>Ok ... What if we don't want to expose our domain structure. Then we need to add list of column names during binding</p> <pre><code>var grid = new WebGrid(persons, columnNames: new [] { "Foo" }); -- or -- grid.Bind(persons, columnNames: new [] { "Foo" }); grid.Column("Foo", format: item =&gt; item.FirstName), grid.Column("LastName"), grid.Column("LivesIn.MyNonExistingField", format: item =&gt; item.LivesIn.City), grid.Column("LivesIn.Country") </code></pre> <p>.. now Foo column has proper sorting url</p> <p>But careful !!! There is another bug.</p> <p>If we add manual column names to binding then all column will be skipped until manual column is found. Example :</p> <pre><code>var grid = new WebGrid(persons, columnNames: new [] { "Foo" }); -- or -- grid.Bind(persons, columnNames: new [] { "Foo" }); grid.Column("FirstName"), grid.Column("Foo", format: item =&gt; item.LastName), grid.Column("LivesIn.MyNonExistingField", format: item =&gt; item.LivesIn.City), grid.Column("LivesIn.Country") </code></pre> <p>... sorting url for column "FirstName" will not be generated correctly ... sortDir=ASC all the time ...to fix this add also a "FirstName" as column name like this:</p> <pre><code>var grid = new WebGrid(persons, columnNames: new [] { "FirstName", "Foo" }); -- or -- grid.Bind(persons, columnNames: new [] { "FirstName", "Foo" }); grid.Column("FirstName"), grid.Column("Foo", format: item =&gt; item.LastName), grid.Column("LivesIn.MyNonExistingField", format: item =&gt; item.LivesIn.City), grid.Column("LivesIn.Country") </code></pre> <p>@Kohen</p> <p>Remove columnNames in your code here</p> <pre><code>var grid = new System.Web.Helpers.WebGrid(Model.SubscriptionList, columnNames: new List&lt;string&gt;(){"Title"}, canPage:false); </code></pre> <p>... or add there all your column names like "ID", "ISP", etc</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload