Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to exclude some datasource fields from a listgrid

    We have some datasources that have a very large number of fields. We will have both a ListGrid and a DynamicForm linked to these datasources. We would like the ListGrid to only show a few select fields from the datasource and the DynamicForm to show all fields. We are currently marking fields that we don't want displayed with detail=true in the datasource and setting the ListGrid.showDetailFields to false. We would like to avoid this however since it requires setting the detail flag on a large number of fields in the datasource. Can we set up which fields from the datasource should be displayed in the ListGrid in the component's defaults?

    For example:
    The ListGrid below should only show the contract_no and contract_yr fields from the datasource. I know that the fields definition does not work as written. How would I set the contractGrid defaults to only show these two fields from the datasource?

    /* CODE */
    contractGridDefaults: {
    _constructor: isc.ListGrid,
    width: "100%",
    height: "300",
    minHeight: "125",
    margin: 5,
    showResizeBar: true,
    autoParent: "panelCanvas",
    autoFitFieldWidths: true,
    autoFitWidthApproach: "both",
    showFilterEditor: true,
    fields: [
    {name="contract_no"},
    {name="contract_yr"}
    ]
    }

    /* DATASOURCE */
    <DataSource
    ID="rscReacctContracts"
    serverType="sql"
    >
    <fields>
    <field name="contract_id" type="integer" title="ContractID" primaryKey="true" hidden="true" />
    <field name="contract_no" type="text" length="100" title="ContractNo" />
    <field name="contract_yr" type="integer" title="ContractYear" format="###0" />
    <field name="reins_prog" type="text" length="200" title="ContractName" />
    <field name="participation_type" type="text" length="20" title="TypeCode" detail="true" />
    <field name="eff_date" type="date" title="Effective" useTextField="true" />
    </fields>
    </DataSource>

    Thanks!

    #2
    This code looks correct - your height and minHeight ought not to be strings, but your fields definition is correct, and should result in only those fields showing.

    Can you show your code that sets the dataSource?

    Comment


      #3
      It basically looks like this:

      isc.ClassFactory.defineClass("ContractsPanel", ScreenPanel).addProperties({
      panelTitle: "Contracts",
      dataSource: "rscReacctContracts",

      contractGridDefaults: {
      _constructor: isc.ListGrid,
      width: "100%",
      height: "300",
      minHeight: "125",
      margin: 5,
      showResizeBar: true,
      autoParent: "panelCanvas",
      autoFitFieldWidths: true,
      autoFitWidthApproach: "both",
      showFilterEditor: true,
      fields: [
      {name="contract_no"},
      {name="contract_yr"}
      ]
      },

      initWidget : function() {
      this.Super("initWidget", arguments);
      this.addAutoChild("contractGrid", {panel: this});

      if (this.contractGrid) {
      this.contractGrid.setDataSource(this.dataSource);
      this.contractGrid.fetchData();
      }
      },

      })


      Comment


        #4
        Since you're choosing a dataSource after the fact, you can pass your field-list as the second param in your call to setDataSource().

        Probably a better approach, though, is to pass the dataSource in the second param you're already passing to addAutoChild(), which will respect the fields from the defaults block - if you also set autoFetchData:true there, or in the grid defaults, you can avoid the manual call to fetchData() as well.
        Last edited by Isomorphic; 27 Dec 2019, 14:15.

        Comment

        Working...
        X