16 Replies Latest reply on Apr 7, 2017 8:54 AM by fgrondin RSS
    praveenp Explorer

    Sorting grid column

    Hi,

    I have one grid which is updating dynamically.
    I want particular column to be sorted automatically, like latest records should be on always top.

    Please provide any solution for this.

    Thanks.

      • Sorting grid column
        paic Collaborator

        Hi Praveen,

         


        I recommend you use the Sort function in your service to deliver the data sorted to the client side.

        (Query also supports Filter and Sort so you can do that too)



          • Re: Sorting grid column
            fgrondin Explorer

            Hi,

            Am i being silly or not ?

            I'm doing this :

             

                        var sort = new Object();

                        sort.name = "myColumnName";

                        sort.ascending = true;

                        Infos.Sort(sort);

             

            But I keep getting that error :

            But the Infos dataTable isn't null.

             

             

            [TransformResultSetStations] :JavaException: java.lang.IllegalArgumentException: Invalid format: "org.mozilla.javascript.Undefined..."

              • Re: Sorting grid column
                pchung Collaborator

                Try this snippet

                 

                 

                var params = {

                  sortColumn: undefined /* STRING */,

                  t: undefined /* INFOTABLE */,

                  ascending: undefined /* BOOLEAN */

                };

                 

                 

                // result: INFOTABLE

                var result = Resources["InfoTableFunctions"].Sort(params);

                  • Re: Sorting grid column
                    fgrondin Explorer

                    I'm still getting the same error. I'm using Thingworx 6.5  with the new snippet.

                      • Re: Sorting grid column
                        pchung Collaborator

                        What does your code look like now?

                          • Re: Sorting grid column
                            fgrondin Explorer

                            It appears to be working. But i have a case where it doesn't work.

                             

                            So how my solution works. The mashup loads, the user selects x property from a dropdown List, and a service is triggered.

                            That service is querying Data from a ms SQL Database. The query returns data. I think the issue come from here.

                             

                            So when a large result set is return, the query works, but it doesn't when I'm getting like 2 rows in the result set.

                            Those 2 rows aren't in the same order that the Stored Procedure was outputting them.

                            (S.P. return row 1 and 2  and in ThingWorx it's receiving 2 and 1 instead).

                             

                            And those items are order by start time in the stored procedure, but for an unknown reason, ThingWorx isn't receiving the good resultSet.

                             

                            So I thought that I would sort them up in Javascript. But when the Data isn't good, then the Sort function doesn't work.

                            When the data is good, the Sort function works.

                             

                            When I'm executing the Stored Procedure outside of Thingworx, it works,

                             

                            Would there be a reason why I'm not getting the same result as the SP ?

                             

                            I'm using SQL(Query) and i'm executing the SP like this:

                            EXECUTE  NameOfSP

                  • Sorting grid column
                    praveenp Explorer

                    I used Sort function, but i am getting following error

                     "Wrapped java.lang.Exception: Unable To Convert From java.lang.String to INFOTABLE Cause: Unable To Convert From java.lang.String to INFOTABLE"

                    var params = {

                        sortColumn: "timestamp" /* STRING /,<br>    t: "ClientName_Events" / INFOTABLE /,<br>    ascending: true / BOOLEAN */
                    };

                    // result: INFOTABLE
                    var result = Resources["InfoTableFunctions"].Sort(params);
                     
                    Here in code :
                    "timestamp" is my column name,
                    "ClientName_Events" is INFOTABLE,

                    Tried BaseType as Text, DateTime and InfoTable.

                    Is am doing anything wrong?

                     



                    • Sorting grid column
                      vladimirros Creator

                      Hi Praveen,

                      In your code you try to pass a String as an Infotable, meaning here: t: "ClientName_Events" /* INFOTABLE */, I presume that you wanted to say actually:

                      t: ClientName_Events /* INFOTABLE */,  ?

                      BR, Vladimir

                      • Re: Sorting grid column
                        qngo Creator

                        Hi, is it possible to sort on many columns, one after another using Sort, like "ORDER BY" of SQL ?

                        • Re: Sorting grid column
                          pjoly Apprentice

                          Hello

                           

                          I would like to do this sorting on a particular column for a Grid generated automatically with "GetImplementingThingsWithData" .

                          How could I access to the associated query to add the "sort" parameter ?

                          Or should I generate the grid by another way ?

                           

                          Thanks

                          Pascal

                            • Re: Sorting grid column
                              qngo Creator

                              Hello, if you can use the service QueryImplementhingsWithData instead, the input parameter "query" can be provided with sort statement

                                • Re: Sorting grid column
                                  pjoly Apprentice

                                  Thanks for advice

                                  The problem is that I have a large number of widgets already associated to the service datas so it will be a large rework (I don't know if there is an easy way to replace the service in the mashup or somewhere without loosing all dependencies ? )

                                   

                                   

                                  I just read that in 7.4 grid will be improved perhaps it will cover my needs with less efforts  ?

                                   

                                  These features will be available at the end of March 2017.

                                  • Advanced Grid: New grid widget with improved design, context menu, multi-column sorting, global search and many more common grid-related features.



                                  But I'll use this service for further mashups

                                • Re: Sorting grid column
                                  qngo Creator

                                  A way to replace the service without loosing all dependencies is export the mashup in .xml, modify the .xml by replacing the service and add other parameters of the new service, then import the .xml. But of course it's not an easy way.

                                   

                                  Or if the Grid simply receive and display the result of GetImplementingThingsWithData, you can create another service which takes the result of that service as input, sort it and return the infotable sorted which is bound to the Grid.



                                    • Re: Sorting grid column
                                      pjoly Apprentice

                                      Great

                                       

                                      I'll edit xml that can be an useful exercie for the future

                                        • Re: Sorting grid column
                                          pjoly Apprentice

                                          Hello

                                           

                                          I have modified with success the mashup using xml but unfortunately the edit of the query function using the Composer doesn't give access to the sort function but only to the filters.

                                           

                                          Si I guess I need to implement the sort function into a service or something similar before to return the datas to the grid.