gsr
12/05/2023, 7:26 PM<cffunction name="QueryToArray" access="public" returntype="array" output="false" hint="This turns a query into an array of structures.">
<cfargument name="Data" type="query" required="yes" />
<cfscript>
var LOCAL = StructNew();
LOCAL.Columns = ListToArray( queryColumnList(arguments.data) );
LOCAL.QueryArray = ArrayNew( 1 );
for (LOCAL.RowIndex = 1 ; LOCAL.RowIndex LTE ARGUMENTS.Data.RecordCount ; LOCAL.RowIndex = (LOCAL.RowIndex + 1)){
LOCAL.Row = StructNew();
for (LOCAL.ColumnIndex = 1 ; LOCAL.ColumnIndex LTE ArrayLen( LOCAL.Columns ) ; LOCAL.ColumnIndex = (LOCAL.ColumnIndex + 1)){
LOCAL.ColumnName = LOCAL.Columns[ LOCAL.ColumnIndex ];
LOCAL.Row[ LOCAL.ColumnName ] = ARGUMENTS.Data[ LOCAL.ColumnName ][ LOCAL.RowIndex ];
}
ArrayAppend( LOCAL.QueryArray, LOCAL.Row );
}
return( LOCAL.QueryArray );
</cfscript>
</cffunction>
but it is still returning me the sorted list, is there any other function or something which returns me the array of objects as they were in the queryScott Steinbeck
12/05/2023, 8:28 PMgsr
12/06/2023, 6:29 PM<cffunction name="sortedData">
<cfargument name="data" required="true" type="any">
<cfset ddata = DeserializeJSON(arguments.data)>
<cfset cquery = QueryNew("id,gametype,gamedate,hometeam,awayteam,location,gametime,gamenumber,notes", "Integer,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar,VarChar")>
<!--- Loop through the JSON array and add rows to the ColdFusion query --->
<cfloop array="#ddata#" index="item">
<cfset QueryAddRow(cquery)>
<cfset QuerySetCell(cquery, "id", item.id)>
<cfset QuerySetCell(cquery, "gametype", item.gameType)>
<cfset QuerySetCell(cquery, "gamedate", item.gameDate)>
<cfset QuerySetCell(cquery, "hometeam", item.homeTeam)>
<cfset QuerySetCell(cquery, "awayteam", item.awayTeam)>
<cfset QuerySetCell(cquery, "location", item.location)>
<cfset QuerySetCell(cquery, "gametime", item.gameTime)>
<cfset QuerySetCell(cquery, "gamenumber", item.gameNumber)>
<cfset QuerySetCell(cquery, "notes", item.notes)>
</cfloop>
<!--- Sort the ColdFusion query --->
<cfset QuerySort(cquery, "id,gametype,gamedate,hometeam,awayteam,location,gametime,gamenumber,notes")>
<!--- Convert the sorted ColdFusion query back to JSON --->
<cfset sortedJson = SerializeJSON(cquery,'struct')>
<cfreturn sortedJson>
</cffunction>
the above functions sorts it properly, but now the problem is whenever i edit a column, it shifts to the end
not sure if its related to this or something else but its a problem nowMatt Jones
12/06/2023, 7:13 PMgsr
12/06/2023, 8:56 PMScott Steinbeck
12/06/2023, 9:03 PMgsr
12/06/2023, 9:16 PMgsr
12/08/2023, 1:55 PMgsr
12/08/2023, 2:14 PMthis fixed it
<cffunction name="QueryToArray" access="public" returntype="array" output="true" hint="This turns a query into an array of structures.">
<cfargument name="Data" type="query" required="yes" />
<cfscript>
var LOCAL = [:];
//dump(QueryColumnList(arguments.data));
LOCAL.Columns = listToArray(arguments.data.getColumnList(false));
//dump(LOCAL.Columns);
LOCAL.QueryArray = ArrayNew( 1 );
for (LOCAL.RowIndex = 1 ; LOCAL.RowIndex LTE ARGUMENTS.Data.RecordCount ; LOCAL.RowIndex = (LOCAL.RowIndex + 1)){
LOCAL.Row = [:];
for (LOCAL.ColumnIndex = 1 ; LOCAL.ColumnIndex LTE ArrayLen( LOCAL.Columns ) ; LOCAL.ColumnIndex = (LOCAL.ColumnIndex + 1)){
LOCAL.ColumnName = LOCAL.Columns[ LOCAL.ColumnIndex ];
LOCAL.Row[ LOCAL.ColumnName ] = ARGUMENTS.Data[ LOCAL.ColumnName ][ LOCAL.RowIndex ];
}
ArrayAppend( LOCAL.QueryArray, LOCAL.Row );
}
//dump(local.QueryArray);
return( LOCAL.QueryArray );
</cfscript>
</cffunction>Matt Jones
12/08/2023, 4:19 PM