Adjusting the Library Configuration

Smartsite 7.7 - ...

When you start the FileTypes DataEditor action, as created within the previous article, the library looks like the example shown below.

Library

 The library configuration xml as generated will look like this:

XML CopyCode image Copy Code
<libraryconfiguration>
  <columns namecolumn="Name">
    <column name="name" caption="Name" />
    <column name="code" caption="Code" />
    <column name="fileextension" caption="FileExtension" />
  </columns>
  <sortorders>
    <sortorder sqlclause="c.Name" caption="ORDERBY_NAME" />
  </sortorders>
  <mastersql>
    select %selectfields% from FileTypes c 
    %joins% 
    where (c.Name like '%%searchfor%%') 
    %wheres% 
  </mastersql>
  <tablealias>c</tablealias>
  <rowdetailssql>
    select c.Nr, c.Name, c.Code, c.FileExtension 
    from FileTypes c 
    where c.Nr in (?) 
  </rowdetailssql>
  <facets>
  </facets>
  <buttons>
  </buttons>
</libraryconfiguration>

The goal is to adjust the xml, so this library looks and behaves just like the built-in FileTypes library.

Columns

The built-in version of this library displays the columns in a different order. Switch the code and fileextension columns to give this library the same order of appearance.

The caption attribute defines the column header and should contain a localization string, that is, it's value (converted to uppercase) will be used to check whether or not there's a localization string available for the specified string. If so, the localized value (Dutch or English, dependent on the user's profile) will be displayed, otherwise the string "as is" will be displayed.

For the fileextension column, specify the localization string FILE_EXTENSION.

As of 7.9, the caption attribute is optional, and the name of the column will also be used as column header/localization string when you do omit the caption attribute.

XML CopyCode image Copy Code
  <columns namecolumn="Name">
    <column name="name" columntype="HtmlString" />
    <column name="fileextension" caption="FILE_EXTENSION" />
    <column name="code" />
  </columns>

Sortorders

The sortorders element includes just one sortorder element, to sort the rows on the name. To be able to sort on the other two columns as well, add two sortorder elements, like this:

XML CopyCode image Copy Code
  <sortorders>
    <sortorder columnname="name" sqlclause="c.Name" />
    <sortorder columnname="code" sqlclause="c.Code" />
    <sortorder columnname="fileextension" sqlclause="c.FileExtension" />
  </sortorders>

Notice: the example above uses the feature that rows can be sorted ascending/descending by clicking on the column header, which is available as of 7.9. This is achieved by specifying the columnname attribute for each sortorder element. For previous versions, in which the sort orders are displayed as a dropdown, you need to specify a caption for each sortorder (caption attribute containing a localization string).

MasterSql

In this example, the mastersql element doesn't need to be changed. However, for example, when the table for which you are creating a DataEditor has additional string columns which must be included within a search operation, you need to alter the where clause and include these columns.

RowDetailsSql

The rowdetailssql element contains the sql query which will be used to retrieve the row details. The specified query should always return the primary key as first column, followed by the columns listed within the columns element (the names must match). The where statement must be specified as: {tablealias}.{primarykey} in (?).

The built-in FileTypes library shows filetype icons within the name column. This is achieved by constructing a html span element as column result for the name column, like so:

XML CopyCode image Copy Code
<rowdetailssql>
 select c.Nr, 
 '&lt;span class="content item filetype_' + c.FileExtension + 
 '"&gt;&lt;span class="icon"&gt;&lt;/span&gt;&lt;/span&gt;' + c.Name as Name,
 c.Code, '.' + c.FileExtension as FileExtension
 from FileTypes c 
 where c.Nr in (?) 
</rowdetailssql>

Notice that in this case, within the columns element, the name column specification must include a columntype attribute set to the value HtmlString.

The icons used in this example are defined within a specific include, which must be specified within the library configuration like this:

XML CopyCode image Copy Code
<libraryconfiguration>
  <cssincludes>
    <include>contenttree-icons.css</include>
  </cssincludes>
  ...
</libraryconfiguration>

Notice: An alternative way of adding these icons to the rendered row results is creating an implementation class (or use inline Custom DataEditor implementation) and override the OnRenderRowDetails method.

LibraryDetails

Librarydetails is an optional element which can be used to specify a sql query (within the sql child element), which should be used when creating the library details for the selected row (see the example below).

XML CopyCode image Copy Code
<librarydetails>
 <sql>
  select c.Nr, c.Name, c.Code, c.FileExtension as FILE_EXTENSION, m.Name as MIME_TYPE
  from FileTypes c
  join MimeTypes m on c.nrMimeType = m.Nr
  where c.Nr in (?)
 </sql>
</librarydetails>

The column names returned from this query will be localized, when there's a corresponding localization string available.

When no librarydetails element is present within the xml, the rowdetails query will be used to construct the library details. 

Facets

The built-in FileTypes library includes a facet on Mime types. To include the same facet within this library, adjust the facets element like this:

XML CopyCode image Copy Code
<facets>
 <facet title="MIME_TYPE">
  <name>mimetype</name>
  <selectfield>nrMimeType</selectfield>
  <query>
   select top 10 ft.Nr, ft.Name, count(ft.Nr) as cnt
   from (%mastersql%) x
   join MimeTypes ft on x.nrMimeType = ft.Nr
   group by ft.Nr, ft.Name
   order by cnt desc
  </query>
 </facet>
</facets>

Buttons

The buttons element can be used to add or remove buttons. In this case, the (default) duplicate button has little use here, so let's remove this button like this:

XML CopyCode image Copy Code
<buttons>
 <remove name="duplicate" />
</buttons>

Adjusted xml

The complete adjusted library configuration xml is shown below.

XML CopyCode image Copy Code
<libraryconfiguration>
  <cssincludes>
    <include>contenttree-icons.css</include>
  </cssincludes>
  <columns namecolumn="Name">
    <column name="name" columntype="HtmlString" />
    <column name="fileextension" caption="FILE_EXTENSION" />
    <column name="code" />
  </columns>
  <sortorders>
    <sortorder columnname="name" sqlclause="c.Name" />
    <sortorder columnname="code" sqlclause="c.Code" />
    <sortorder columnname="fileextension" sqlclause="c.FileExtension" />
  </sortorders>
  <mastersql>
  select %selectfields% from FileTypes c 
  %joins% 
  where (c.Name like '%%searchfor%%') 
  %wheres% 
 </mastersql>
  <tablealias>c</tablealias>
  <rowdetailssql>
  select c.Nr, 
     '&lt;span class="content item filetype_' + c.FileExtension + 
     '"&gt;&lt;span class="icon"&gt;&lt;/span&gt;&lt;/span&gt;' + c.Name as Name,
     c.Code, '.' + c.FileExtension as FileExtension
  from FileTypes c 
  where c.Nr in (?) 
 </rowdetailssql>
  <librarydetails>
    <sql>
      select c.Nr, c.Name, c.Code, c.FileExtension as FILE_EXTENSION, m.Name as MIME_TYPE
      from FileTypes c
      join MimeTypes m on c.nrMimeType = m.Nr
      where c.Nr in (?)
    </sql>
  </librarydetails>
  <facets>
    <facet title="MIME_TYPE">
      <name>mimetype</name>
      <selectfield>nrMimeType</selectfield>
      <query>
        select top 10 ft.Nr, ft.Name, count(ft.Nr) as cnt
        from (%mastersql%) x
        join MimeTypes ft on x.nrMimeType = ft.Nr
        group by ft.Nr, ft.Name
        order by cnt desc
      </query>
    </facet>
  </facets>
  <buttons>
    <remove name="duplicate" />
  </buttons>
</libraryconfiguration>