Share via


How to: Customize a Viewer Using "M"

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

This topic shows how to customize viewers by using Microsoft code name “M”. This is the third topic in the "Quadrant" Advanced Customization Tutorial.

The contents of the “M” file that is used in this topic can be found in the Example section.

Note

This tutorial assumes that you have already completed the How to: Create a Database from "M" in "Quadrant" tutorial, which creates the PetShop database in an instance of SQL Server by using “M”.

To customize viewers in "Quadrant" by using “M”

  1. On the View menu, click Explorer, and then click MSPetShop4. The database opens in a new workpad.

  2. Expand the Database icon.

  3. Expand the dbo2 icon under Database.

  4. Drag the Product icon under dbo2 to the workspace. (Alternatively, double-click the Product icon.) This opens a workpad named Product that displays the Product table from the database.

  5. In the upper-right corner of the Product workpad, click the viewer switch icon (the small white triangle) and click Table to view the workpad in the original table viewer.

  6. On the Workpad menu, click View Source. You are now viewing “M” source code that defines the instances that describe the table view for the Product workpad.

  7. Replace the “M” code for the Microsoft.Quadrant.Templates module with the following code. This changes the viewer’s DisplayName from Table to Table From M.

    module Microsoft.Quadrant.Templates
    {
        import Microsoft.Quadrant;
    
        Templates
        {
            Table_0
            {
                Name => "Table_0",
                DisplayName => "Table From M",
                Pattern => "CollectionViewer",
                InputDataType => CatalogReferences.dbo2_Product_0,
                InitialMaxWidth => 600,
    
                .Invocations
                {
                    Table_0_Root
                    {
                        DeclaringTemplate => Templates.Table_0,
                        TemplateName => "TableViewer",
                        Position => 0,
                    },
                },
            }
        }
    }
    
  8. Replace the “M” code for the Microsoft.Quadrant.Viewers module with the following code. This removes all the table columns except CategoryId and Name.

    module Microsoft.Quadrant.Viewers
    {
        import Microsoft.Quadrant.Templates;
    
        TableConfigurations
        {
            Table_0
            {
                Invocation => Invocations.Table_0_Root,
                TableColumns =>
                {
                    {
                        DisplayName => "CategoryId",
                        IsVisible => true,
                        Position => 1,
                        PropertyName => "CategoryId",
                    },
                    {
                        DisplayName => "Name",
                        IsVisible => true,
                        Position => 3,
                        PropertyName => "Name",
                    },
                }
            }
        }
    }
    
  9. Right-click the “M” file and click Deploy. In the Deploy dialog box, choose Use existing database and select the existing Quadrant Repository from the drop-down list. Click Deploy. Click OK in the installation success confirmation dialog.

  10. In the upper-right corner of the Product workpad, click the viewer switch icon (the small white triangle). You can see the newly created custom view Table From M in the list.

  11. Click Table From M. The workpad is now displayed in our customized view with only two table columns as specified.

In this topic, you have learned how to create a customized view by using “M” code.

Example

module Microsoft.Quadrant
{
    CatalogReferences
    {
        dbo2_Product_0
        {
            ModuleName => "dbo2",
            Name => "Product",
        },
    }
}

module Microsoft.Quadrant.Templates
{
    import Microsoft.Quadrant;

    Templates
    {
        Table_0
        {
            Name => "Table_0",
            DisplayName => "Table From M",
            Pattern => "CollectionViewer",
            InputDataType => CatalogReferences.dbo2_Product_0,
            InitialMaxWidth => 600,

            .Invocations
            {
                Table_0_Root
                {
                    DeclaringTemplate => Templates.Table_0,
                    TemplateName => "TableViewer",
                    Position => 0,
                },
            },
        }
    }
}

module Microsoft.Quadrant.Viewers
{
    import Microsoft.Quadrant.Templates;

    TableConfigurations
    {
        Table_0
        {
            Invocation => Invocations.Table_0_Root,
            TableColumns =>
            {

                {
                    DisplayName => "CategoryId",
                    IsVisible => true,
                    Position => 1,
                    PropertyName => "CategoryId",
                },
                {
                    DisplayName => "Name",
                    IsVisible => true,
                    Position => 3,
                    PropertyName => "Name",
                },
            }
        }
    }
}

See Also

Other Resources

"Quadrant" Pet Shop Tutorial
"Quadrant" Tutorials
"Quadrant" Advanced Customization Tutorial
Customizing the "Quadrant" Data Viewing Experience