Navigation: DbNetEditCore >

Methods

 

 

 

 

 

AddLinkedControl(DbNetSuiteCore)

 

This method takes an instance of DbNetGridCore or DbNetEditCore  as a parameter and makes it a child of the form on which the method is called. The child control will then select all the records where the foreign key of the child control matches the primary key of the parent form.

 

...

customersEdit.AddLinkedControl(ordersGrid);

...

 

Demo

 

...

customersEdit.AddLinkedControl(ordersEdit);

...

 

Demo

 

AddList<T>(IEnumerable<T> list, HttpContext httpContext = null)

 

This generic method can be used when you specify List as the data source type in the Constructor and want to assign the data as a list of typed objects.  The method takes a second optional parameter of HttpContext which if supplied causes the list data to be cached on the server for the duration of the session instead of being sent to the server every time. Any modifcations to the data are handled through the onJsonUpdated event handler which must be assigned.

 

...

DbNetEditCore ProductsEdit = new DbNetEditCore(DataSourceType.List);

ProductsEdit.AddList(Model.Products);

ProductsEdit.Column(nameof(Product.ProductID)).PrimaryKey();

...

 

 

Bind(EventType, string)

 

This method assigns a client-side JavaScript method to a client-side grid event which enables additonal levels of customisation. The method is passed 2 arguments. The first is the type of the event and the second is the name of the JavaScript function that will be called by the event. The JavaScript function is always passed an instance of the client-side form control and an optional second argument that contains additional information specific to the type of event. For more information about each event type click here

 

...

employeesEdit.Bind(EventType.OnConfigureBinaryData, "configureImageFileName");

employeesEdit.Bind(EventType.OnFormElementValidationFailed, "configureValidationMessage");

employeesEdit.Bind(EventType.OnFormElementCreated, "configureFormElement");

...

<script type="text/javascript" class="source">

        function configureFormElement(sender, args) {

            switch (args.columnName)

            {

                case "notes":

                    args.formElement.rows = 4;

                    args.formElement.cols = 20;

                    break;

            }

        }

 

        function configureImageFileName(sender, args) {

            var fileName = sender.columnValue("photopath");

            args.fileName = fileName.split('/').pop().replace(".bmp", ".jpg");

        }

 

        String.prototype.replaceLast = function (what, replacement) {

            var pcs = this.split(what);

            var lastPc = pcs.pop();

            return pcs.join(what) + replacement + lastPc;

        };

 

        function configureValidationMessage(sender, args) {

            if (args.key == "titleofcourtesy") {

                const pattern = sender.formElement(args.key).attr("pattern");

                const readablePattern = pattern.split('|').join(', ').replaceLast(",", " or");

                args.value = `Title Of Courtesy should have a value of: ${readablePattern}`

            }

        }

</script>

 

Demo

 

Column(string) : DbNetEditCoreColumn,

Column(string[]) : DbNetEditCoreColumn

 

The Column method creates a DbNetEditCoreColumn object which can be used to assign properties to a column or columns in the form using a fluent style API

 

...

DbNetEditCore productsForm = new DbNetEditCore("northwind", "products");

productsForm.Column("discontinued").DataType(typeof(Boolean));

productsForm.Bind(EventType.OnRecordSelected, "disableFormForInactiveProducts");

productsForm.Column("supplierid").Lookup(new Lookup("suppliers", "supplierid", "companyname")).Label("Supplier");

productsForm.Column("categoryid").Lookup(new Lookup("categories", "categoryid", "categoryname")).Label("Category");

productsForm.Column(new string[] { "ProductName", "Discontinued" }).Browse();

@productsForm.Render()

...

 

Demo

 

 

Render()

 

This method is called after the component has been fully configured and will render the form at the point in the Razor page at which it is invoked unless the optional 3rd Id parameter is supplied to the constructor in which case the grid will be rendered inside the HTML element with the Id specified.

 

 

 

 

 

 

 

 

 

 

Copyright © 2023 DbNetLink