Search This Blog

Serenity Using SERGEN generated Grid in a Dialog

Suppose we generated code using SERGEN for 2 tables (Region,Territories) of NorthWind Sample DataBase. DDL Statements of these tables are
		CREATE TABLE region (
region_id smallint NOT NULL PRIMARY KEY,
region_description bpchar NOT NULL
);
CREATE TABLE territories (
territory_id character varying(20) NOT NULL PRIMARY KEY,
territory_description bpchar NOT NULL,
region_id smallint NOT NULL,
FOREIGN KEY (region_id) REFERENCES region
);


Create following function in file TerritoriesGrid.ts

        public set_Filter(value: string): void {
            //We created the QuickFilter on TerritoriesRow.Fields.RegionDescription in 
            //file TerritoriesRow.cs using [QuickFilter] attribute
            //We are just setting that QuickFilter with below statement		
            this.findQuickFilter(Serenity.StringEditor,
                TerritoriesRow.Fields.RegionDescription).value = value;
        }
Add the grid property in RegionDialog.ts file.

	private myGrid: TerritoriesGrid;
Create following function in RegionDialog.ts file.

	protected afterLoadEntity() {
            super.afterLoadEntity();
            $('.s-DialogContent').append('<div id="MyGrid"></div>');
            this.myGrid = new TerritoriesGrid($('#MyGrid'));
            this.myGrid.set_Filter(this.entity.Regiondescription);
            this.myGrid.refresh();
        }
Furthermore, we can remove buttons,toolbars and columns or fields from TerritoriesGrid and RegionDialog as per our requirement.


No comments:

Post a Comment

Web Statistics