Hello I have a problem with sorting the rows of a source table
I would like that based on a column of a global table, the column "ORDEN" determine the order of the complete rows of the source
I know it could be with code but I do not have a clear idea of how to do it
I share a model and images
I hope you can help me
thank you
Answer by Jörg Vogel · Jul 11 at 05:16 AM
Please consider use an SQL approach. A table query can sort a table in the system memory in a local table. Then you clone the result to the original global table.
SQL Queries in References of Manual, please take a look in the section “Getting Data Out of the Query”. The clause of WHERE isn’t necessary at all. You can omit it of the query.
Please ask here again if you need more help on SQL in a new question!
Here is an example model that uses @Jörg Vogel's approach. I created a new table called "OrderedPlan" and placed the following code in it's On Reset trigger.
Table current = param(1); //Table node Table QueryTable = Table.query("Select * FROM Plan ORDER BY Orden ASC"); QueryTable.cloneTo(current);
This gave me an ordered table.
Plan Table:
OrderdPlan Table:
hi @Benjamin W2 and @Jörg Vogel
Thank you very much to both of you, I already managed to do what I was looking for
the model works perfectly
Answer by Aaron C · Jul 10 at 06:53 PM
Assuming that you don't want to sort in Excel and directly import, you have a few options. One that comes to mind is first create a new Global Table. Copy your Source1 table into it. Add an additional column ORDEN and fill in its values to the corresponding ItemName. Then open the OnRunStart script and type the following:
Table newGlobalTable = Table("NewGlobalTableName"); /* This is whatever you name the new table*/
newGlobalTable.sort([5],[1]); /* This will sort the table based on the 5th column in descending order*/
Table sourceTable = getvarnode(Model.find("Source1"), "sequence");
int i = 1;
while (i <= 11) /* This will fill the source table with the new global table values */
{
sourceTable.as(Table)[i][1] = newGlobalTable[i][1];
sourceTable.as(Table)[i][2] = newGlobalTable[i][2]
sourceTable.as(Table)[i][3] = newGlobalTable[i][3];
sourceTable.as(Table)[i][4] = newGlobalTable[i][4];
sourceTable.as(Table)[i][5] = newGlobalTable[i][5];
i++;
}
hi @Aaron C
I already saw your answer,
I can not understand what I have to do I can not do what your code shows, could you support me by uploading a code where it does?
please I would appreciate it very much
hi @Aaron C
I already made a model with the idea that you recommended me, but it does not order the rows in the way that I specify in the column,
I hope you can review it and give me feedback
I share the model that I made
thank you so much
How to Setup the source by an input value 1 Answer
How can I let the crane wait, till the processor he has loaded, has finished? 1 Answer
Adding Members to Timetable Dynamically/Command (HC) 1 Answer
Change the queue property with code 2 Answers
Pull Requirement Depends on Downstream States help? 1 Answer
© 1993- FlexSim Software Products, Inc. All Rights Reserved.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.