2 year anniversary

Dbgrid bounded to a database query


PageHome.ts

//Simple dbgrid bounded to a query
import V = require(“VCL/VCL”);
 
export class PageHome extends V.TPage {
  constructor() {
    super();
 
    //this is a unsecure way to run a query (for a secure way refer to TQueryRemote)
    var qur = new V.TQuery(this);
    qur.SQL = “SELECT CustomerKey, FirstName, LastName, Gender FROM Customers”;
    qur.open();
 
    //create a grid on the scren
    var grd = new V.TDBGrid(this, “grid”);
    grd.Dataset = qur; //bind the grid to the dataset
    grd.ShowSelectedRecord = true;
    grd.PageSize = 15;
 
    var col = grd.createColumn(“FirstName”);
    col.Header = “First Name”;
    //clicking a column change the query dataset position
    col.onClicked = () => {
      var customerKey = qur.getFieldValue(‘customerKey’);
      //do somthing with the customer key
    }
 
    //another way to initialize a column
    var col = grd.createColumn(“Lastname”,”Last Name”);
  }
}

 

PageHome.html

<div>
<div id=”grid”/>
</div>

 

This entry was posted in Code Snippet and tagged , . Bookmark the permalink.