/// <summary> /// If <paramref name="cellItem"/> is null, cell specific styles are not included. /// </summary> /// <param name="cellItem"></param> /// <returns></returns> internal string GetCellStyle(WebGridCellEx <T> cellItem) { if (cellItem == null) { throw new ArgumentNullException("cellItem"); } var style = string.Join("", _conditionalStyles.Where(p => p.Key == null || p.Key(cellItem)).Select(p => p.Value)); return(style); }
internal HelperResult GetCellHtml(WebGridCellEx <T> cellItem) { object result = null; if (_conditionalCellHtml != null) { // First check for an explicitly true predicate, and then check for the null predicate result = _conditionalCellHtml.Where(p => p.Key != null && p.Key(cellItem)).Select(p => p.Value(cellItem)).FirstOrDefault() ?? _conditionalCellHtml.Where(p => p.Key == null).Select(p => p.Value(cellItem)).FirstOrDefault(); } if (result != null) { // We are done. One of the conditions was specified and result is the HTML } else if (MetaData == null) { // This column is not bound to a property. Empty HTML. } else if (cellItem.Value == null || cellItem.Value.ToString() == string.Empty) { // Value is null so NullDisplayText result = MetaData.NullDisplayText; } else if (string.IsNullOrEmpty(MetaData.DisplayFormatString)) { // DisplayFormatString not specified. Render the value as is. result = cellItem.Value; } else { // Apply the DisplayFormatString result = string.Format(MetaData.DisplayFormatString, cellItem.Value); } return(new HelperResult(tw => { var helper = result as HelperResult; if (helper != null) { helper.WriteTo(tw); return; } var htmlString = result as IHtmlString; if (htmlString != null) { tw.Write(htmlString); return; } if (result != null) { tw.Write(HttpUtility.HtmlEncode(result)); } })); }
internal IDictionary <string, object> GetCellAttributes(WebGridCellEx <T> cellItem) { var dict = _attributesAccessor == null ? null : _attributesAccessor(cellItem); if (_cellAttributes != null) { if (dict == null) { dict = new Dictionary <string, object>(_cellAttributes); } else { foreach (var item in _cellAttributes) { dict[item.Key] = item.Value; } } } return(dict); }