And one more question: how can I find out if the DynamicList contain any data? The task is to suggest adding a first item to the empty list. It has some filters so checking if my catalog is empty is not the thing which will help here.
:( It is a complicated query so I would not like to repeat it due to it's hard to support. If there is a way to use the one which is built in into the DynamicList? Or maybe there is a simpler way? How can I understand if there is any item displayed in the form item having this DynamicList as a data source?
#4 Not working because When You change filter and list was empty befor and filled after changing filter you'll have CurrentRow is Undefined but there is data in list. I think Silvia need something like
Code
QueryBuilder = New QueryBuilder;
BuilderText = "SELECT
| Order.Ref
|FROM
| Document.Order AS Order";
QueryBuilder.Text = BuilderText;
DataSourceDescription = New DataSourceDescription(DocListControl);
QueryBuilder.DataSource = DataSourceDescription;
QueryBuilder.Execute();
TZ = QueryBuilder.Result.Unload();
If TZ.Count() > 0 Then
//not empty
Else
//empty
EndIf;
but this need big memory for large datas. I think Silvia have to use another algoritms, whithout checking data in controls.
Silvia Ashley, good question! The fact that the filling DynamicList may influence the selection of previously established Programming. On the other hand - I never will have to solve such problems, but just can not come across ... Figure 1: Perform as suggested earlier request but we do not need to perform the entire query, not just run " Select * ..." but "Select FIRST 1 * ...." Figure 2: forcibly reset selections if they are installed, check for emptiness, "Items.List.CurrentRow" and then restore the selection if it was set.
Thank you guys! Escander, the Figure 2 looks like what I need, could you please explain it? I can't get how to reset selections and why CurrentRow will work in that case, while Anatoly says it will not work after DynamicList filters changes.
Thank you, Anatoly, but to use this method I will have to synchronize the query in the DynamicList and in this additional query. Which I wouldn't like to do... If possible.
In the general course in the morning immediately evident that the optimal solution is unique! Use the query - this is optimal, but more often to check it does not reach. The code below for a list form catalog customers.
Code
&AtServerNoContext
Function TestOnServer()
Query = New Query;
Query.Text =
"SELECT TOP 1
| Catalog.Ref
|FROM
| Catalog.Контрагенты AS Catalog";
= Query.Execute();
Return Result.IsEmpty();
EndFunction
&AtClient
Function ListEmpty()
ii=True;
If Lists.Filter.Items.Count()=0 Then
If ValueIsFilled(Items.List.CurrentRow) Then
ii=False;
EndIf;
Else
If ValueIsFilled(Items.List.CurrentRow) Then
ii=False;
Else
ii=TestOnServer();
EndIf;
EndIf;
Return ii;
EndFunction
&AtClient
Procedure OnOpen(Cancel)
ff=ListEmpty();
EndProcedure
Not always DynamicList based on a query can be used and a dynamic read and fill DynamicList with data having no connection to the dat abase(meaning a programmatic). Get text queries will be a function:
Code
&AtServer
Function QueryFromFormOnServer()
TxtQ="":
If List.CustomQuery Then
TxtQ=List.QueryText:
EndIf
Return TxtQ;
EndFunction