Custom query parameter name

Sep 19, 2012 at 4:30 PM

Hi

I would like to customize the query parameter name for the pager, but that does not seem to be possible? Is there any way to do it?

Coordinator
Sep 20, 2012 at 9:45 AM
Edited Sep 20, 2012 at 9:45 AM

Sorry, there is no such functionality until Grid.Mvc 2.0.5

You need update to 2.0.5 version and use overload WithPaging method:

 

Html.Grid(Model).Columns(columns =>
            {
               ...
            }).WithPaging(20, 5, "MyCustomParameter")

 

If you not using Htmlhlper methods - you need to cast Pager property to GridPager and setup QueryParameterName property:

 

EnablePaging = true;
            Pager.PageSize = 30;
            ((GridPager)Pager).QueryParameterName = "MyCustomParameterName";

 

Sep 20, 2012 at 11:47 AM

Thank you very much for such a quick fix for the problem.

Also I added an extension method to the IGridColumnCollection to enable use of a few data annotations to auto title and format the columns. Just thought I would share it with you, if you wanted to implement something similar

 

        /// <summary>
        /// Add a column with data annotations.
        /// Currently supporting display format string and display name.
        /// </summary>
        /// <typeparam name="T">The type of the grid</typeparam>
        /// <typeparam name="TKey">Type of the data</typeparam>
        /// <param name="constraint">Lambda expression for the member to use</param>
        /// <returns>Returns the added column</returns>
        public static IGridColumn<T> AddData<T, TKey>(this IGridColumnCollection<T> collection, Expression<Func<T, TKey>> constraint) where T : class
        {
            IGridColumn<T> column = collection.Add(constraint);
            MemberExpression exp = constraint.Body as MemberExpression; 
            ModelMetadata metadata = ModelMetadataProviders.Current
                  .GetMetadataForProperty(() => null, typeof(T), exp.Member.Name);

            bool named = !String.IsNullOrEmpty(metadata.DisplayName);
            bool formatted = !String.IsNullOrEmpty(metadata.DisplayFormatString);
            if (named && formatted)
                return column.Titled(metadata.DisplayName).Format(metadata.DisplayFormatString);

            if (named)
                return column.Titled(metadata.DisplayName);

            if (formatted)
                return column.Format(metadata.DisplayFormatString);

            return column;
        }