var fields = [
    {
        fieldName: "ToMonth",
        dataType: "number",
    },
    {
        fieldName: "Month",
        dataType: "number",
    },
    {
        fieldName: "Year",
        dataType: "number",
    },
    {
        fieldName: "InterestRate",
        dataType: "number",
    },
    {
        fieldName: "SaveCost",
        dataType: "number",
    },
    {
        fieldName: "SaveMaturity",
        dataType: "number",
    },
    {
        fieldName: "CurrentSave",
        dataType: "number",
    },
];

var columns = [
    {
        name: "ToMonth",
        fieldName: "ToMonth",
        width: "100",
        header: {
            text: "납입 횟수",
        },
        editor: {
            type: "number"
        },
        styleName: "right-column",
    },
    {
        name: "Month",
        fieldName: "Month",
        width: "100",
        header: {
            text: "남은 횟수",
        },
        editor: {
            type: "number"
        },
        styleName: "right-column",
    },
    {
        name: "InterestRate",
        fieldName: "InterestRate",
        width: "100",
        numberFormat: "0.00",
        header: {
            text: "이율",
        },
        editor: {
            type: "number"
        },
        styleName: "right-column",
    },
    {
        name: "SaveCost",
        fieldName: "SaveCost",
        width: "100",
        numberFormat: "#,##0",
        header: {
            text: "납입금",
        },
        editor: {
            type: "number"
        },
        styleName: "right-column",
    },
    {
        name: "SaveMaturity",
        fieldName: "SaveMaturity",
        width: "100",
        numberFormat: "#,##0",
        header: {
            text: "만기금액",
        },
        editor: {
            type: "number"
        },
        styleName: "right-column",
    },
    {
        name: "CurrentSave",
        fieldName: "CurrentSave",
        width: "100",
        numberFormat: "#,##0",
        header: {
            text: "현재잔액",
        },
        editor: {
            type: "number"
        },
        styleName: "right-column",
    },
];

const data = [
    {
        ToMonth: 23,
        Month: 41,
        Year: 3,
        InterestRate: 0.15,
        SaveCost: 51000,
        SaveMaturity: 14950650,
        CurrentSave: 9304950,
    },
    {
        ToMonth: 3,
        Month: 37,
        Year: 3,
        InterestRate: 0.38,
        SaveCost: 14000,
        SaveMaturity: 7801080,
        CurrentSave: 1108520,
    },
    {
        ToMonth: 13,
        Month: 36,
        Year: 3,
        InterestRate: 0.32,
        SaveCost: 112000,
        SaveMaturity: 50480640,
        CurrentSave: 20805120,
    },
    {
        ToMonth: 5,
        Month: 28,
        Year: 2,
        InterestRate: 0.2,
        SaveCost: 84000,
        SaveMaturity: 15523200,
        CurrentSave: 4704000,
    },
];

document.addEventListener("DOMContentLoaded", function () {
    RealGrid.setLicenseKey(
        "upVcPE+wPOmtLjqyBIh9RkM/nBOseBrflwxYpzGZyYm9cY8amGDkiMnVeQKUHJDjW2y71jtk+wteqHQ1mRMIXzEcGIrzZpzzNTakk0yR9UcKS69Wn2kI83Uszabo3mU0LUipz0P8BheMHilNXwOhKViPkoEUbYPLyVfdcZjXXt8="
    );

    const provider = new RealGrid.LocalDataProvider();
    const gridView = new RealGrid.GridView("realgridContainer");
    gridView.setDataSource(provider);

    provider.setFields(fields);
    gridView.setColumns(columns);

    gridView.displayOptions.rowHeight = -1;

    provider.setRows(data);
});