Page 1 of 1

Sorting table data by column

Posted: Mon Jul 21, 2008 3:55 pm
by nate
Hello,

I seem to have a little program with table sorting:
Let's say I have a table with 2 columns: ClientName and Details. So far, data in the table is unsorted, while I'd love them to be sorted by Client alphabetically. Like, first would go Mr. Adams with his description, then Mr. Bartleby with his, etc.
I tried to switch to the grid view, right-click the column and select "sort ascending/ descending" - but that does not seem to work in the right way :(

All I could manage - was to have data in separate rows sorted, while changes should have been applied to the whole table.

Please help!

P.S. all this applies to DocBook documentation - if that helps

Re: Sorting table data by column

Posted: Mon Jul 21, 2008 5:14 pm
by sorin_ristache
Hello,

Do you mean you want to sort the rows of a table in a DocBook document by modifying the DocBook XML document? The action Sort ascending available on the popup menu should do the trick when you right click on the column with the person names and select the sorting action. If it does not work for you please post a small sample XML document that contains the table that you want to sort alphabetically.


Regards,
Sorin

Re: Sorting table data by column

Posted: Tue Jul 22, 2008 8:45 am
by nate
Hello, thanks for the reply,

the code chunk can be like this:

Code: Select all

<informaltable>
<tgroup cols="2">
<colspec colnum="2" colname="col2" colwidth="*"/>
<colspec colnum="1" colname="col1" colwidth="*"/>

<thead>
<row>
<entry colname="col1">
<para>Client</para>
</entry>
<entry colname="col2">
<para>Description</para>
</entry>
</row>
</thead>

<tbody>
<row>
<entry colname="col1">
<para>Bartleby</para>
</entry>
<entry colname="col2">
<para>some description text for Bart</para>
</entry>
</row>
<row>
<entry colname="col1">
<para>Adams</para>
</entry>
<entry colname="col2">
<para>some description text for Adams</para>
</entry>
</row>
<row>
<entry>
<para>Collins</para>
</entry>
<entry>
<para>some description for Collins</para>
</entry>
</row>
<row>
<entry>
<para>Aarons</para>
</entry>
<entry>
<para>some description text for Aarons</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
Wished result is a table sorted in the following way:

Code: Select all


Client		Description

Aarons some description text for Aarons
Adams some description text for Adams
Bartleby some description text for Bart
Collins some description for Collins
Thanks!

Re: Sorting table data by column

Posted: Wed Jul 23, 2008 3:28 pm
by sorin_ristache
Hello,

The entry elements containing the person names are not sibling elements, that is they have different parent elements instead of a common parent element. That means they cannot displayed as a table in the Grid mode of the XML editor so they cannot be sorted with an action Sort ascending. You have to write and apply an XSLT stylesheet to your DocBook XML document which sorts the row elements of the informaltable based on the value of the entry element with the person name:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:db="http://docbook.org/ns/docbook">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="db:tbody">
<xsl:copy>
<xsl:apply-templates select="db:row">
<xsl:sort select="db:entry[1]"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Sorin

Re: Sorting table data by column

Posted: Thu Jul 24, 2008 10:04 am
by nate
Thanks!

Re: Sorting table data by column

Posted: Wed Oct 08, 2008 5:34 pm
by george_amazon
So, there's no native table sorting mechanism in oXygen 9? Help talks about an A->Z icon, which I can't find--nothing when you right click on a table column.

Re: Sorting table data by column

Posted: Thu Oct 09, 2008 10:14 am
by tavy
george_amazon wrote:So, there's no native table sorting mechanism in oXygen 9? Help talks about an A->Z icon, which I can't find--nothing when you right click on a table column.
No, there is no table sorting in Author mode in v9. Only the Grid mode has sorting, but that does not help you with tables. I'm guessing that's what you found in the Help.
However table sorting would be a very useful feature, so we added it to our bug tracking tool and we will probably implement it in a future version.

Regards,
Adrian Buza

Re: Sorting table data by column

Posted: Thu Oct 09, 2008 10:31 am
by george_amazon
Great, Adrian. Thanks!

Only other suggestion is to revise the Help. It's not always very oriented toward the wysiwyg version of oXygen.

Re: Sorting table data by column

Posted: Fri Sep 07, 2012 9:41 pm
by alexanderthelange
In 2008, Adrian Buza wrote:
> we will probably implement it in a future version

Hi Adrian or other support folks,

It's 2012 now. Any news if this sort-by-column feature is on the roadmap?

Thanks!
Alex

Re: Sorting table data by column

Posted: Mon Sep 10, 2012 12:18 pm
by adrian
Hello Alex,

This was rather difficult to implement at that time (the Author mode had just been introduced in v9.0/2008), so it got pushed further back.

This feature request is now scheduled for v14.2, but it could still be pushed back. I've added your comment and increased its priority, so hopefully it will stick with v14.2.

Regards,
Adrian