Skip to content

Commit

Permalink
chore: cleanup code example
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding authored Sep 19, 2023
1 parent 95d837b commit 496246a
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions examples/example-trading-esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ <h2>View Source:</h2>
let refreshRate = 25;
let timer;

var dataView;
var grid;
var data = [];
var columns = [
let dataView;
let grid;
let data = [];
let columns = [
{
id: 'currency', name: 'Currency', field: 'currency', sortable: true, width: 75,
formatter: (row, cell, value) => `<img src="https://flags.fmcdn.net/data/flags/mini/${value.substring(0, 2).toLowerCase()}.png" width="18"/>&nbsp;${value}`
Expand Down Expand Up @@ -178,7 +178,7 @@ <h2>View Source:</h2>
},
];

var options = {
const options = {
editable: true,
enableAddRow: true,
enableCellNavigation: true,
Expand All @@ -188,13 +188,13 @@ <h2>View Source:</h2>
rowHeight: 28
};

var sortcol = "title";
var sortdir = 1;
var percentCompleteThreshold = 0;
var searchString = "";
let sortcol = "title";
let sortdir = 1;
let percentCompleteThreshold = 0;
let searchString = "";

function sumTotalsFormatter(totals, columnDef, grid) {
var val = totals.sum && totals.sum[columnDef.field];
let val = totals.sum && totals.sum[columnDef.field];
if (val != null) {
return "total: $" + ((Math.round(parseFloat(val)*100)/100));
}
Expand Down Expand Up @@ -373,7 +373,7 @@ <h2>View Source:</h2>
startSimulation();
}, refreshRate);

var groupItemMetadataProvider = new SlickGroupItemMetadataProvider();
const groupItemMetadataProvider = new SlickGroupItemMetadataProvider();
dataView = new SlickDataView({
groupItemMetadataProvider: groupItemMetadataProvider,
inlineFilters: true
Expand All @@ -383,33 +383,18 @@ <h2>View Source:</h2>
grid.registerPlugin(groupItemMetadataProvider);
grid.setSelectionModel(new SlickRowSelectionModel());

var columnpicker = new SlickColumnPicker(columns, grid, options);
const columnpicker = new SlickColumnPicker(columns, grid, options);

grid.onCellChange.subscribe(function (e, args) {
dataView.updateItem(args.item.id, args.item);
});

grid.onAddNewRow.subscribe(function (e, args) {
var item = {"num": data.length, "id": "new_" + (Math.round(Math.random() * 10000)), "title": "New task", "duration": "1 day", "percentComplete": 0, "start": "01/01/2009", "finish": "01/01/2009", "effortDriven": false};
const item = {"num": data.length, "id": "new_" + (Math.round(Math.random() * 10000)), "title": "New task", "duration": "1 day", "percentComplete": 0, "start": "01/01/2009", "finish": "01/01/2009", "effortDriven": false};
Utils.extend(item, args.item);
dataView.addItem(item);
});

grid.onKeyDown.subscribe(function (e) {
// select all rows on ctrl-a
if (e.which != 65 || !e.ctrlKey) {
return false;
}

var rows = [];
for (var i = 0; i < dataView.getLength(); i++) {
rows.push(i);
}

grid.setSelectedRows(rows);
e.preventDefault();
});

grid.onSort.subscribe(function (e, args) {
sortdir = args.sortAsc ? 1 : -1;
sortcol = args.sortCol.field;
Expand All @@ -432,10 +417,10 @@ <h2>View Source:</h2>
});

// wire up the slider to apply the filter to the model
var highlight = document.getElementById("highlightDuration");
const highlight = document.getElementById("highlightDuration");
highlight.oninput = (e) => highlightDuration = e.target.value;

var slider = document.getElementById("refreshRateSlider");
const slider = document.getElementById("refreshRateSlider");
slider.oninput = (e) => refreshRate = e.target.value;

// initialize the model after all the events have been hooked up
Expand Down

0 comments on commit 496246a

Please sign in to comment.