Loading ...
Sorry, an error occurred while loading the content.

Issue with datatable from html markup and sorting

Expand Messages
  • apapf
    I have a datatable that is created from HTML markup. One of the columns has the following html (give or take): 50%
    Message 1 of 6 , Dec 4, 2008
    • 0 Attachment
      I have a datatable that is created from HTML markup. One of the
      columns has the following html (give or take):

      <a href="somelink.html?userid=1">50%</a>

      Everything renders fine, but when that column is sorted it is sorted
      by the user id not the %. My goal was to have the percentage used for
      the sorting.

      I tried a custom parser but that changes the actual display. What is
      the right way to leave the link in the display and have the sorting
      based on the %.

      Thanks.
    • Arun Kumar Roy
      Please tell me , what is the key given for the field
      Message 2 of 6 , Dec 4, 2008
      • 0 Attachment
        Please tell me , what is the key given for the field



        On Fri, Dec 5, 2008 at 9:46 AM, apapf <apapf@...> wrote:

        I have a datatable that is created from HTML markup. One of the
        columns has the following html (give or take):

        <a href="somelink.html?userid=1">50%</a>

        Everything renders fine, but when that column is sorted it is sorted
        by the user id not the %. My goal was to have the percentage used for
        the sorting.

        I tried a custom parser but that changes the actual display. What is
        the right way to leave the link in the display and have the sorting
        based on the %.

        Thanks.


      • Frank
        The key for the field is friendrating . Thanks.
        Message 3 of 6 , Dec 5, 2008
        • 0 Attachment
          The key for the field is 'friendrating'.

          Thanks.

          --- In ydn-javascript@yahoogroups.com, "Arun Kumar Roy" <arun@...> wrote:
          >
          > Please tell me , what is the key given for the field
          >
          >
          >
        • Satyam
          The problem here is that you do have two different pieces of information in the same cell. The best would be to split them into its two components. That can
          Message 4 of 6 , Dec 6, 2008
          • 0 Attachment
            The problem here is that you do have two different pieces of information
            in the same cell.

            The best would be to split them into its two components. That can be
            easily done by overriding DataSource doBeforeCallback method, which is
            meant for this purpose. There you will find all your HTML table parsed
            into a JavaScript array of objects which will constitute the records of
            the DataTable. One of the properties of these objects will contain the
            string with the link and the text. What you can do then is to extract
            each of the fields, possibly via regular expressions and store them in
            separate properties in each of the records. And make sure they are
            stored as actual numbers, not strings of digits, so they will sort
            correctly later on. In your column definitions you would use the names
            of those new properties as column keys. This solution would turn this
            single column into two separate columns. That may not be what you want.

            If you want a single column then you have to decide what would be the
            value the user would mean to sort by when clicking on that column
            header, in this case you say it is the percentage (which makes sense
            since that is what the user sees). Then create the column with the key
            set to the property name you gave the percentage value. Sorting will
            then happen based on the percentage values stored in the recordset. If
            you still want the link, then you will have to use a custom formatter
            for that column.

            Satyam


            apapf wrote:
            > I have a datatable that is created from HTML markup. One of the
            > columns has the following html (give or take):
            >
            > <a href="somelink.html?userid=1">50%</a>
            >
            > Everything renders fine, but when that column is sorted it is sorted
            > by the user id not the %. My goal was to have the percentage used for
            > the sorting.
            >
            > I tried a custom parser but that changes the actual display. What is
            > the right way to leave the link in the display and have the sorting
            > based on the %.
            >
            > Thanks.
            >
            >
            > ------------------------------------
            >
            > Yahoo! Groups Links
            >
            >
            >
            > ------------------------------------------------------------------------
            >
            >
            > No virus found in this incoming message.
            > Checked by AVG - http://www.avg.com
            > Version: 8.0.176 / Virus Database: 270.9.14/1829 - Release Date: 04/12/2008 14:59
            >
            >
          • Frank
            Thanks for the reply. I just want 1 column. So am I better off having the table itself show the number value? E.g. 96, and use custom formatter to add the %
            Message 5 of 6 , Dec 6, 2008
            • 0 Attachment
              Thanks for the reply.

              I just want 1 column. So am I better off having the table itself show
              the number value? E.g. 96, and use custom formatter to add the % sign
              and the link?

              I think I tried that, but I can try it again if that's the right approach.


              --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
              >
              > The problem here is that you do have two different pieces of
              information
              > in the same cell.
              >
              > The best would be to split them into its two components. That can be
              > easily done by overriding DataSource doBeforeCallback method, which is
              > meant for this purpose. There you will find all your HTML table parsed
              > into a JavaScript array of objects which will constitute the records of
              > the DataTable. One of the properties of these objects will contain the
              > string with the link and the text. What you can do then is to extract
              > each of the fields, possibly via regular expressions and store them in
              > separate properties in each of the records. And make sure they are
              > stored as actual numbers, not strings of digits, so they will sort
              > correctly later on. In your column definitions you would use the names
              > of those new properties as column keys. This solution would turn this
              > single column into two separate columns. That may not be what you want.
              >
              > If you want a single column then you have to decide what would be the
              > value the user would mean to sort by when clicking on that column
              > header, in this case you say it is the percentage (which makes sense
              > since that is what the user sees). Then create the column with the key
              > set to the property name you gave the percentage value. Sorting will
              > then happen based on the percentage values stored in the recordset. If
              > you still want the link, then you will have to use a custom formatter
              > for that column.
              >
              > Satyam
              >
              >
              > apapf wrote:
              > > I have a datatable that is created from HTML markup. One of the
              > > columns has the following html (give or take):
              > >
              > > <a href="somelink.html?userid=1">50%</a>
              > >
              > > Everything renders fine, but when that column is sorted it is sorted
              > > by the user id not the %. My goal was to have the percentage used for
              > > the sorting.
              > >
              > > I tried a custom parser but that changes the actual display. What is
              > > the right way to leave the link in the display and have the sorting
              > > based on the %.
              > >
              > > Thanks.
              > >
              > >
              > > ------------------------------------
              > >
              > > Yahoo! Groups Links
              > >
              > >
              > >
              > >
              ------------------------------------------------------------------------
              > >
              > >
              > > No virus found in this incoming message.
              > > Checked by AVG - http://www.avg.com
              > > Version: 8.0.176 / Virus Database: 270.9.14/1829 - Release Date:
              04/12/2008 14:59
              > >
              > >
              >
            • Satyam
              You have to let the formatter add the formatting. If you store the % sign then the record would contain strings and they would be sorted like 1%, 11%, 2% and
              Message 6 of 6 , Dec 6, 2008
              • 0 Attachment
                You have to let the formatter add the formatting. If you store the %
                sign then the record would contain strings and they would be sorted like
                1%, 11%, 2% and so on. You have to store numbers, which would then be
                sorted right, and add the % in the formatter.

                Satyam


                Frank wrote:
                > Thanks for the reply.
                >
                > I just want 1 column. So am I better off having the table itself show
                > the number value? E.g. 96, and use custom formatter to add the % sign
                > and the link?
                >
                > I think I tried that, but I can try it again if that's the right approach.
                >
                >
                > --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
                >
                >> The problem here is that you do have two different pieces of
                >>
                > information
                >
                >> in the same cell.
                >>
                >> The best would be to split them into its two components. That can be
                >> easily done by overriding DataSource doBeforeCallback method, which is
                >> meant for this purpose. There you will find all your HTML table parsed
                >> into a JavaScript array of objects which will constitute the records of
                >> the DataTable. One of the properties of these objects will contain the
                >> string with the link and the text. What you can do then is to extract
                >> each of the fields, possibly via regular expressions and store them in
                >> separate properties in each of the records. And make sure they are
                >> stored as actual numbers, not strings of digits, so they will sort
                >> correctly later on. In your column definitions you would use the names
                >> of those new properties as column keys. This solution would turn this
                >> single column into two separate columns. That may not be what you want.
                >>
                >> If you want a single column then you have to decide what would be the
                >> value the user would mean to sort by when clicking on that column
                >> header, in this case you say it is the percentage (which makes sense
                >> since that is what the user sees). Then create the column with the key
                >> set to the property name you gave the percentage value. Sorting will
                >> then happen based on the percentage values stored in the recordset. If
                >> you still want the link, then you will have to use a custom formatter
                >> for that column.
                >>
                >> Satyam
                >>
                >>
                >> apapf wrote:
                >>
                >>> I have a datatable that is created from HTML markup. One of the
                >>> columns has the following html (give or take):
                >>>
                >>> <a href="somelink.html?userid=1">50%</a>
                >>>
                >>> Everything renders fine, but when that column is sorted it is sorted
                >>> by the user id not the %. My goal was to have the percentage used for
                >>> the sorting.
                >>>
                >>> I tried a custom parser but that changes the actual display. What is
                >>> the right way to leave the link in the display and have the sorting
                >>> based on the %.
                >>>
                >>> Thanks.
                >>>
                >>>
                >>> ------------------------------------
                >>>
                >>> Yahoo! Groups Links
                >>>
                >>>
                >>>
                >>>
                >>>
                > ------------------------------------------------------------------------
                >
                >>> No virus found in this incoming message.
                >>> Checked by AVG - http://www.avg.com
                >>> Version: 8.0.176 / Virus Database: 270.9.14/1829 - Release Date:
                >>>
                > 04/12/2008 14:59
                >
                >>>
                >
                >
                >
                > ------------------------------------
                >
                > Yahoo! Groups Links
                >
                >
                >
                > ------------------------------------------------------------------------
                >
                >
                > No virus found in this incoming message.
                > Checked by AVG - http://www.avg.com
                > Version: 8.0.176 / Virus Database: 270.9.14/1832 - Release Date: 05/12/2008 9:57
                >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.