Desktop version

Main > Forum > 1C:Enterprise Platform > Studying 1C:Enterprise platform > How to change column set of a table on a form programmatically

Forum

Search UsersRules
How to change column set of a table on a form programmatically
#1
Interested
Points:: 0
Joined:: Apr 5, 2012

Hi.

I did not see how to add Columns in FormDataCollection type. Is there way to add Columns in formdatacollection by script?

Profile
#2
Guest
Points::
Joined::

Columns are form items too. Which columns do you want to add?

Profile
#3
Interested
Points:: 0
Joined:: Apr 5, 2012

In managed form I have a form attribute, type is ValueTable. So, in backgound working some algorithms in which content of columns may change (in some moments there may be 5 colums, in some moment 7 or 9..). So I need to change content of columns in type "formdatacollection". But there I couldn't find in FomrDataCollection property like "Columns" in which I could add columns which I really need to show to user.

Profile
#4
Interested
Points:: 0
Joined:: Apr 5, 2012

Is there any possibility to control columns in FormDataCollection? Or it's "Impossible" as uncle James says :)

Profile
#5
Guest
Points::
Joined::

I can recommend to change visibility of predefined items on form.

But if you are sure that you want to use non static query for your list with different column set, you can use the following script as an example:

Code
   // obtaining the data
   Query = New Query;
   Query.Text = QueryText;

   QueryResult = Query.Execute();

   SelectionDetailRecords = QueryResult.Choose();

   QueryResultTableObject = New ValueTable;
   QueryResultTableObject.Clear();
   QueryResultTableObject.Columns.Clear();
   
   For Each Column In QueryResult.Columns Do
      QueryResultTableObject.Columns.Add(Column.Name, Column.ValueType, Column.Name, Column.Width);
   EndDo;

   While SelectionDetailRecords.Next() Do
      Row = QueryResultTableObject.Add();
      FillPropertyValues(Row, SelectionDetailRecords);
   EndDo;

   // removing form items
   QueryResultTableItem = Items.Find("QueryResultTable");
   If QueryResultTableItem <> Undefined Then
      Items.Delete(QueryResultTableItem);
   EndIf;
   
   // creating and filling form attributes
   AttributesToAdd = New Array();
   AttributesToDelete = New Array();
   
   RootAttributes = GetAttributes();
   For Each Attribute In RootAttributes Do
      If Attribute.Path = "" And Attribute.Name = "QueryResultTable" Then
         AttributesToDelete.Add("QueryResultTable");
         Break;
      EndIf;
   EndDo;
   
   QueryResultTableType = New TypeDescription("ValueTable");
   QueryResultTableAttribute = New FormAttribute("QueryResultTable", QueryResultTableType);
   AttributesToAdd.Add(QueryResultTableAttribute);
   For Each Column In QueryResultTableObject.Columns Do
      ColumnAttribute = New FormAttribute(Column.Name, Column.ValueType, "QueryResultTable");
      AttributesToAdd.Add(ColumnAttribute);
   EndDo;
   
   ChangeAttributes(AttributesToAdd, AttributesToDelete);
   ValueToFormAttribute(QueryResultTableObject, "QueryResultTable");
   
   // creating form items
   QueryResultTableItem = Items.Add("QueryResultTable", Type("FormTable"), Items.ResultOutputGroup);
   QueryResultTableItem.DataPath = "QueryResultTable";
   
   For Each Column In QueryResultTableObject.Columns Do
      ColumnItem = Items.Add("QueryResultTable" + Column.Name, 
              Type("FormField"), QueryResultTableItem);
      ColumnItem.Type = FormFieldType.InputField;
      ColumnItem.DataPath = "QueryResultTable." + Column.Name;
   EndDo;

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.