@using Financial.Models
@using C1.Web.Mvc.Grid
@model IEnumerable<Company>
@{ 
    ViewBag.Title = "ASP.NET MVC FlexGrid with dynamic updates";
}

<script type="text/template" id="template1">
    <div id="{{uid}}">
        <div class="value"></div>
        <div class="chg"></div>
        <div class="glyph"><span></span></div>
        <div class="spark"></div>
    </div>
    <script type="text/javascript">
        formatDynamicCell('{{uid}}', {{row}}, {{column}});
    <\/script>
</script>

<div class="container">
    <h1>Trading information</h1>
    <p>
        Trading information with dynamic updates.
    </p>
</div>
<label>
    Custom Cells
    <input id="customCells" type="checkbox" checked="checked">
</label>
<label>
    Auto Update
    <input id="autoUpdate" type="checkbox" checked="checked">
</label>
<label>
    Update Interval (ms)
    @(Html.C1().ComboBox()
        .Id("updateInterval")
        .Bind((List<object>)ViewBag.Intervals)
        .SelectedValue(100).IsEditable(false)
        .OnClientSelectedIndexChanged("updateInterval_SelectedIndexChanged"))
</label>
<label>
    Batch Size (#items)
    @(Html.C1().ComboBox()
        .Id("batchSize")
        .Bind((List<object>)ViewBag.BatchSizes)
        .SelectedValue(5).IsEditable(false)
        .OnClientSelectedIndexChanged("batchSize_SelectedIndexChanged"))
</label>

@(Html.C1().FlexGrid<Company>()
    .Id("theGrid")
    .AutoGenerateColumns(false)
    .Bind(Model)
    .IsReadOnly(true)
    .Columns(columns =>
    {
        columns.Add(column => column.Binding("Name").Width("220"));
        columns.Add(column => column.Binding("Bid").Format("n2").Width("220").CellTemplate(ctb=>ctb.TemplateId("template1")));
        columns.Add(column => column.Binding("Ask").Format("n2").Width("220").CellTemplate(ctb => ctb.TemplateId("template1")));
        columns.Add(column => column.Binding("LastSale").Header("Last Sale").Format("n2").Width("220").CellTemplate(ctb => ctb.TemplateId("template1")));
        columns.Add(column => column.Binding("BidSize").Header("Bid Size").Format("n0"));
        columns.Add(column => column.Binding("AskSize").Header("Ask Size").Format("n0"));
        columns.Add(column => column.Binding("LastSize").Header("Last Size").Format("n0"));
        columns.Add(column => column.Binding("Volume").Header("Volume").Format("n0"));
        columns.Add(column => column.Binding("QuoteTime").Header("Quote Time").Format("hh:mm:ss").Align("center"));
        columns.Add(column => column.Binding("TradeTime").Header("Trade Time").Format("hh:mm:ss").Align("center"));
    })
    .SelectionMode(SelectionMode.Row)
    .AllowSorting(false)
    .OnClientFormatItem("formatItem")
    .OnClientUpdatingView("updatingView")
)