Exemple #1
0
 public static IGridColumnOptions <T> Format <T>(this IGridColumnOptions <T> opts, string formatString)
 {
     //Contract.Requires( opts != null );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.Format = formatString;
     return(opts);
 }
Exemple #2
0
 public static IGridColumnOptions <T> NotSortable <T>(this IGridColumnOptions <T> opts)
 {
     //Contract.Requires( opts != null );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.Sortable = false;
     return(opts);
 }
Exemple #3
0
 public static IGridColumnOptions <T> Title <T>(this IGridColumnOptions <T> opts, string title)
 {
     //Contract.Requires( opts != null );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.Title = new MvcHtmlString(title);
     return(opts);
 }
Exemple #4
0
 public static IGridColumnOptions <T> Title <T>(this IGridColumnOptions <T> opts, Func <object, IHtmlString> titleTemplate)
 {
     //Contract.Requires( opts != null );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.Title = titleTemplate(null);
     return(opts);
 }
Exemple #5
0
        public static IGridColumnOptions <T> Class <T>(this IGridColumnOptions <T> opts, string className)
        {
            //Contract.Requires( opts != null );
            //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
            var a = new { @class = className };

            return(opts.HeaderAttributes(a).CellAttributes(a));
        }
Exemple #6
0
 public static IGridColumnOptions <T> HeaderAttributes <T>(this IGridColumnOptions <T> opts, object attributes)
 {
     //Contract.Requires( opts != null );
     //Contract.Requires( attributes != null );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.HeaderAttributes = opts.HeaderAttributes.Merge(AttrsFrom(attributes));
     return(opts);
 }
Exemple #7
0
 public static IGridColumnOptions <T> Sortable <T>(this IGridColumnOptions <T> opts, string sortProperty)
 {
     //Contract.Requires( opts != null );
     //Contract.Requires( !String.IsNullOrEmpty( sortProperty ) );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.Sortable     = true;
     opts.SortProperty = sortProperty;
     return(opts);
 }
Exemple #8
0
 public static IGridColumnOptions <T> CellAttributes <T>(this IGridColumnOptions <T> opts, object attributes)
 {
     //Contract.Requires( opts != null );
     //Contract.Requires( attributes != null );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.CellAttributes = opts.CellAttributes.Merge(
         AttrsFrom(attributes)
         .ToDictionary(kvp => kvp.Key, kvp => (Func <T, string>)(_ => kvp.Value)));
     return(opts);
 }
Exemple #9
0
 public static IGridColumnOptions <T> CellAttribute <T>(this IGridColumnOptions <T> opts, string attributeName, Func <T, string> getValue)
 {
     //Contract.Requires( opts != null );
     //Contract.Requires( !String.IsNullOrEmpty( attributeName ) );
     //Contract.Requires( getValue != null );
     //Contract.Ensures( //Contract.Result<IGridColumnOptions<T>>() != null );
     opts.CellAttributes = opts.CellAttributes.Merge(
         EnumerableEx.Return(0).ToDictionary(_ => attributeName, _ => getValue));
     return(opts);
 }
        /// <summary>
        /// Modifies a column in such a way that it becomes sortable on the client-side.
        /// NOTE: if paging is involved, then this sorting will only occur across current page, since other pages do not
        /// get loaded into the browser at all.
        /// </summary>
        /// <param name="col">Column to modify</param>
        /// <param name="html">HTML helper</param>
        /// <param name="getJavaScriptSortValue">A function that for each grid row returns a Javascript expression that evaluates to a Javascript value that will be used as the row's value when sorting</param>
        public static IGridColumnOptions <TRow> ClientSideSort <TRow>(this IGridColumnOptions <TRow> col, HtmlHelper html, Func <TRow, string> getJavaScriptSortValue, bool ascendingByDefault = true)
        {
            //Contract.Requires( col != null );
            //Contract.Requires( getJavaScriptSortValue != null );
            //Contract.Ensures( //Contract.Result<IGridColumnOptions<TRow>>() != null );

            var widget = html.Render <IGridClientSortColumn>();

            widget.On(col, getJavaScriptSortValue, ascendingByDefault);
            return(col);
        }
Exemple #11
0
        public void On <TRow>(IGridColumnOptions <TRow> col, Func <TRow, string> getJavaScriptSortValue, bool ascendingByDefault)
        {
            col.CellAttributes =
                col.CellAttributes.Merge(
                    new SortedList <string, Func <TRow, string> >
            {
                { "sort-value", getJavaScriptSortValue }
            });

            col.Title(_ => Html.Partial <Views.Grid.GridClientSortColumnTitle>().WithModel(new GridClientSortColumnModel
            {
                InnerTitle         = col.Title,
                AscendingByDefault = ascendingByDefault
            }));
        }