Announcement

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

    Edit many-to-many DataSources

    Here are my DataSources:

    Main DataSource
    Code:
    <DataSource 
    	schema="ca"
    	dbName="CA"
    	tableName="ca_template"
    	ID="ca_template"
    	dataSourceVersion="1"
    	serverType="sql"
    >
    	<fields>
    		<field implicitSequence="true" primaryKey="true" name="id" type="sequence" hidden="true" sequenceName="ca_template_id_seq" />
    		<field name="scaption" length="255" type="text" title="Template" required="true" />
    		<field name="sdescription" length="2000" type="text" title="Description" required="true" />
    	</fields>
    </DataSource>
    Additional DataSource
    Code:
    <DataSource 
    	schema="ca"
    	dbName="CA"
    	tableName="ca_requirement"
    	ID="ca_requirement"
    	dataSourceVersion="1"
    	serverType="sql"
    >
    	<fields>
    		<field implicitSequence="true" primaryKey="true" name="id" type="sequence" hidden="true" sequenceName="ca_requirement_id_seq" />
    		<field name="code" length="255" type="text" title="Code" required="true" />
    		<field name="scaption" length="255" type="text" title="Requirement" required="true" />
    		<field name="sdescription" length="2000" type="text" title="Description" required="true" />
    		<field name="requirement_id" type="integer" title="Parent requirement" required="false" foreignKey="ca_requirement.id" />
    		<field name="standard_id" type="integer" title="Standard" required="true" foreignKey="ca_standard.id" />
    	</fields>
    </DataSource>
    Relation
    Code:
    <DataSource 
    	schema="ca"
    	dbName="CA"
    	tableName="ca_template_requirement"
    	ID="ca_template_requirement"
    	dataSourceVersion="1"
    	serverType="sql"
    >
    	<fields>
    		<field implicitSequence="true" primaryKey="true" name="id" type="sequence" hidden="true" sequenceName="ca_template_requirement_id_seq" />
    		<field name="template_id" type="integer" title="Template" required="true" foreignKey="ca_template.id" />
    		<field name="requirement_id" type="integer" title="Requirement" required="true" foreignKey="ca_requirement.id" />
    	</fields>
    </DataSource>
    Tell me please what is the best way to edit many-to-many DataSources? I want something like - when I select row in ListGrid with main datasource entries, I see TreeGrid with additional datasource entries with pre-selected entries according to "ca_template_requirement" relation.

    #2
    You can make use of the dataSourceField.includeFrom feature to help with this setup.

    You can add a template_id field to the "requirement" DS, and have it includeFrom "ca_template_requirement.template_id".

    You then have your main grid bound to the "template" listgrid and your "detail" TreeGrid bound to the "requirement" dataSource.

    Then, when a record is selected in the LG bound to "template", you just need to setCriteria() on the TG like:
    Code:
    tg.setCriteria({template_id: lg.getSelectedRecord().id});
    Let us know if this need further clarification!

    Thanks
    Isomorphic Software

    Comment


      #3
      I cannot add a template_id field to the "requirement" DS. I have many-to-many relation (ca_template_requirement). One template can have many requirements and one requirement can be on many templates.

      As of setCriteria I also cannot use it because I need to have ability to select some new requirements while editing template (to create new record in ca_template_requirement relation).

      After long time in searching thru man I've done this.

      Code:
      <SCRIPT SRC=/sc/isomorphic/DataSourceLoader?dataSource=ca_template,ca_requirement,ca_template_requirement></SCRIPT>
      <SCRIPT>
          function DSGetTR (data) 
          {
              var length = data.getLength(), element = null;
              for (var i = 0; i < length; i++) 
              {
                  element = data.get(i);
                  rowToSelect = requirementList.getOriginalData().find({id: element.requirement_id});
                  requirementList.selectRecord(rowToSelect,true);
              }
          }
          function recordClick () 
          {
              // SKIPPED
              isc.DataSource.get("ca_template_requirement").fetchData({template_id: templateGrid.getSelectedRecord().id}, "DSGetTR(data)");
          }
          // SKIPPED
          isc.ListGrid.create({
              ID:"templateGrid",
              // SKIPPED
              dataSource:"ca_template",
              recordClick:"recordClick()"
          })
          // SKIPPED
          isc.TreeGrid.create({
              ID: "requirementList",
              // SKIPPED
              dataSource:"ca_requirement",
              selectionAppearance:"checkbox",
              // SKIPPED
          })
          // SKIPPED
      </SCRIPT>
      With this code I can get the result: I click on record in templateGrid and get all records, according to ca_template_requirement relation, checked.

      Maybe there is some straighter way to get this result?

      Comment


        #4
        Well, any ideas about simplification of treegrid's checkbox checking?

        Comment

        Working...
        X