Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Client/features/dataTableProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,24 @@ class DataTableView implements IDataTableView {
// ── Initialize Simple-DataTables grid ──
var headings = tableData.columns.map(function(c) { return c.name; });
var data = tableData.rows;
// Map Kusto column types to Simple-DataTables sort types so numeric and
// date columns sort correctly instead of as text.
var columnSettings = [];
tableData.columns.forEach(function(c, i) {
var kustoType = c.type;
var sortType =
(kustoType === 'int' || kustoType === 'long' ||
kustoType === 'real' || kustoType === 'decimal') ? 'number'
: (kustoType === 'datetime') ? 'date'
: (kustoType === 'bool') ? 'boolean'
: null;
if (sortType) {
columnSettings.push({ select: i, type: sortType });
}
});
var grid = new simpleDatatables.DataTable(tableEl, {
data: { headings: headings, data: data },
columns: columnSettings,
perPage: 100,
perPageSelect: [50, 100, 500, 1000],
searchable: true,
Expand Down
22 changes: 20 additions & 2 deletions src/Server/Utilities/ResultData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ public static ResultTable FromDataTable(DataTable table)
})
.ToImmutableList();

var columnTypes = columns.Select(c => c.Type).ToArray();
var rows = table.Rows.OfType<DataRow>()
.Select(r => r.ItemArray.Select(ConvertCellValue).ToImmutableList())
.Select(r => r.ItemArray.Select((v, i) => ConvertCellValue(v, columnTypes[i])).ToImmutableList())
.ToImmutableList();

return new ResultTable
Expand Down Expand Up @@ -176,11 +177,28 @@ public DataTable ToDataTable()
return table;
}

private static object? ConvertCellValue(object? value)
private static object? ConvertCellValue(object? value, string kustoType)
{
if (value == null || value == DBNull.Value)
return null;

// The Kusto ADO.NET client surfaces bool columns as sbyte/byte (0 or 1).
// Convert to a real bool so JSON serialization emits `true`/`false`
// instead of numeric 0/1.
if (kustoType == "bool")
{
return value switch
{
bool b => b,
sbyte sb => sb != 0,
byte b => b != 0,
short s => s != 0,
int i => i != 0,
long l => l != 0,
_ => value
};
}

// Convert to JSON-safe types
return value switch
{
Expand Down
Loading