/// <summary> /// Return the JavaScript that is used to initialize jqGrid with given options. /// </summary> /// <returns>The JavaScript that initializes jqGrid with give options</returns> /// <exception cref="System.InvalidOperationException"> /// <list type="bullet"> /// <item><description>TreeGrid and data grouping are both enabled.</description></item> /// <item><description>Rows numbers and data grouping are both enabled.</description></item> /// <item><description>Dynamic scrolling and data grouping are both enabled.</description></item> /// <item><description>TreeGrid and GridView are both enabled.</description></item> /// <item><description>SubGrid and GridView are both enabled.</description></item> /// <item><description>AfterInsertRow event and GridView are both enabled.</description></item> /// </list> /// </exception> public static IHtmlContent JqGridJavaScript(this IHtmlHelper htmlHelper, JqGridOptions options) { ValidateJqGridConstraints(options); IUrlHelperFactory urlHelperFactory = (IUrlHelperFactory)htmlHelper.ViewContext.HttpContext.RequestServices.GetService(typeof(IUrlHelperFactory)); options.ApplyModelMetadata(htmlHelper.MetadataProvider, urlHelperFactory.GetUrlHelper(htmlHelper.ViewContext)); StringBuilder javaScriptBuilder = new StringBuilder(); javaScriptBuilder.AppendFormat("$('#{0}')", options.Id) .AppendJqGridScript(options, false); return(new HtmlString(javaScriptBuilder.ToString())); }
public void ApplyModelMetadata_MappedColumn_JsonMappingIsSet() { Mock <IModelMetadataProvider> metadataProviderStub = new Mock <IModelMetadataProvider>(); metadataProviderStub.Setup(m => m.GetMetadataForProperties(SOME_GRID_MODEL_TYPE)).Returns(new[] { (ModelMetadata) new JqGridColumnModelMetadata(SOME_GRID_COLUMN_TYPE, nameof(SomeGridModel.MappedColumn), SOME_GRID_MODEL_TYPE) }); Mock <IUrlHelper> urlHelperStub = new Mock <IUrlHelper>(); JqGridOptions <SomeGridModel> options = new JqGridOptions <SomeGridModel>(SOME_GRID_ID); options.ApplyModelMetadata(metadataProviderStub.Object, urlHelperStub.Object); Assert.Equal(SOME_JSON_MAP, options.ColumnsModels.Single(c => c.Name == nameof(SomeGridModel.MappedColumn)).JsonMapping); }
public void ApplyModelMetadata_DefaultColumn_KeyIsFalse() { Mock <IModelMetadataProvider> metadataProviderStub = new Mock <IModelMetadataProvider>(); metadataProviderStub.Setup(m => m.GetMetadataForProperties(SOME_GRID_MODEL_TYPE)).Returns(new[] { (ModelMetadata) new JqGridColumnModelMetadata(SOME_GRID_COLUMN_TYPE, nameof(SomeGridModel.DefaultColumn), SOME_GRID_MODEL_TYPE) }); Mock <IUrlHelper> urlHelperStub = new Mock <IUrlHelper>(); JqGridOptions <SomeGridModel> options = new JqGridOptions <SomeGridModel>(SOME_GRID_ID); options.ApplyModelMetadata(metadataProviderStub.Object, urlHelperStub.Object); Assert.False(options.ColumnsModels.Single(c => c.Name == nameof(SomeGridModel.DefaultColumn)).Key); }
/// <summary> /// Return the JavaScript that is used to initialize jqGrid with given options. /// </summary> /// <returns>The JavaScript that initializes jqGrid with give options</returns> /// <exception cref="System.InvalidOperationException"> /// <list type="bullet"> /// <item><description>TreeGrid and data grouping are both enabled.</description></item> /// <item><description>Rows numbers and data grouping are both enabled.</description></item> /// <item><description>Dynamic scrolling and data grouping are both enabled.</description></item> /// <item><description>TreeGrid and GridView are both enabled.</description></item> /// <item><description>SubGrid and GridView are both enabled.</description></item> /// <item><description>AfterInsertRow event and GridView are both enabled.</description></item> /// </list> /// </exception> public static IHtmlContent JqGridJavaScript(this IHtmlHelper htmlHelper, JqGridOptions options) { ValidateJqGridConstraints(options); options.ApplyModelMetadata(htmlHelper.MetadataProvider); StringBuilder javaScriptBuilder = new StringBuilder(); javaScriptBuilder.AppendFormat("$({0}).jqGrid({{", GetJqGridGridSelector(options, false)).AppendLine() .AppendJavaScriptObjectStringArrayField(JqGridOptionsNames.COLUMNS_NAMES_FIELD, options.ColumnsNames) .AppendColumnsModels(options) .AppendOptions(options) .Append("})"); javaScriptBuilder.AppendLine(";"); return(new HtmlString(javaScriptBuilder.ToString())); }