internal static void ApplyModelMetadata(this JqGridOptions options, IModelMetadataProvider metadataProvider, IUrlHelper urlHelper)
        {
            IJqGridStronglyTypedOptions jqGridStronglyTypedOptions = options as IJqGridStronglyTypedOptions;

            if (jqGridStronglyTypedOptions != null)
            {
                foreach (ModelMetadata columnMetadata in metadataProvider.GetMetadataForProperties(jqGridStronglyTypedOptions.ModelType))
                {
                    if (IsValidForColumn(columnMetadata))
                    {
                        options.AddColumn(columnMetadata.GetDisplayName(), CreateJqGridColumnModel(columnMetadata, urlHelper));
                    }
                }

                if (jqGridStronglyTypedOptions.ActionsColumn != null)
                {
                    if (jqGridStronglyTypedOptions.ActionsColumn.Position >= options.ColumnsModels.Count)
                    {
                        options.AddColumn(_actionsColumnDisplayName, CreateActionsColumnModel(jqGridStronglyTypedOptions.ActionsColumn));
                    }
                    else
                    {
                        options.InsertColumn(jqGridStronglyTypedOptions.ActionsColumn.Position, _actionsColumnDisplayName, CreateActionsColumnModel(jqGridStronglyTypedOptions.ActionsColumn));
                    }
                }
            }

            if (options.SubgridEnabled)
            {
                if (options.SubgridOptions != null)
                {
                    options.SubgridOptions.ApplyModelMetadata(metadataProvider, urlHelper);
                }
                else if (options.SubgridModel != null)
                {
                    options.SubgridModel.ApplyModelMetadata(metadataProvider);
                }
            }
        }
Example #2
0
        public void AppendColumnsModels_XmlMappingIsNull_ScriptDoesNotContainXmlMapOption()
        {
            IJqGridJsonService jqGridJsonServiceStub = new Mock <IJqGridJsonService>().Object;

            StringBuilder javaScriptBuilder = new StringBuilder();
            JqGridOptions options           = new JqGridOptions(SOME_GRID_ID);

            options.AddColumn(SOME_COLUMN_NAME, new JqGridColumnModel(SOME_COLUMN_NAME));

            javaScriptBuilder = javaScriptBuilder.AppendColumnsModels(options, jqGridJsonServiceStub, false);

            Assert.DoesNotContain(XML_MAP_OPTION, javaScriptBuilder.ToString());
        }
        internal static void ApplyModelMetadata(this JqGridOptions options, IModelMetadataProvider metadataProvider)
        {
            Type jqGridOptionsType = options.GetType();

            if (jqGridOptionsType.IsConstructedGenericType && jqGridOptionsType.GetGenericTypeDefinition() == typeof(JqGridOptions <>))
            {
                foreach (ModelMetadata columnMetadata in metadataProvider.GetMetadataForProperties(jqGridOptionsType.GenericTypeArguments[0]))
                {
                    if (IsValidForColumn(columnMetadata))
                    {
                        options.AddColumn(columnMetadata.GetDisplayName(), CreateJqGridColumnModel(columnMetadata));
                    }
                }
            }
        }
Example #4
0
        public void AppendOptions_KeyIsTrue_ScriptContainsKeyOption()
        {
            IJqGridJsonService jqGridJsonServiceStub = new Mock <IJqGridJsonService>().Object;

            StringBuilder javaScriptBuilder = new StringBuilder();
            JqGridOptions options           = new JqGridOptions(SOME_GRID_ID);

            options.AddColumn(SOME_COLUMN_NAME, new JqGridColumnModel(SOME_COLUMN_NAME)
            {
                Key = true
            });

            javaScriptBuilder = javaScriptBuilder.AppendColumnsModels(options, jqGridJsonServiceStub, false);

            Assert.Contains($"{KEY_OPTION}true", javaScriptBuilder.ToString());
        }
Example #5
0
        public void AppendOptions_JsonMappingIsNotNull_ScriptContainsJsonMapOption()
        {
            IJqGridJsonService jqGridJsonServiceStub = new Mock <IJqGridJsonService>().Object;

            StringBuilder javaScriptBuilder = new StringBuilder();
            JqGridOptions options           = new JqGridOptions(SOME_GRID_ID);

            options.AddColumn(SOME_COLUMN_NAME, new JqGridColumnModel(SOME_COLUMN_NAME)
            {
                JsonMapping = SOME_JSON_MAP
            });

            javaScriptBuilder = javaScriptBuilder.AppendColumnsModels(options, jqGridJsonServiceStub, false);

            Assert.Contains($"{JSON_MAP_OPTION}'{SOME_JSON_MAP}'", javaScriptBuilder.ToString());
        }