How to make a column with always fixed data in a Datatable? MVC JS

Asked

Viewed 47 times

0

Hello. I have a Datatable that is returning BD values, but I need only one column to always have fixed values that will not come from the BD (in this case, it is a column with the months of the year). However, I cannot change the Datatable structure directly in HTML as I am building it as follows:

    var colsBaseLT = [
    { data: null, className: 'col-sm-2 text-center', title: 'Base Hour', defaultContent: ''},
    { data: 'Quantity', className: 'col-sm-2 text-center', title: 'Quantidade', defaultContent: ''},
    { data: 'Year', className: 'col-sm-2 text-center', title: 'Ano', defaultContent: ''},
];

function CreateTable() {
    DataTablesAjaxPagination("#tableBaseHour", colsBaseLT, null, null, 12, 'BaseHour');
    $.ajax({
        url: urlCreateTable,
        type: 'POST',
        success: function (result) {
            dataTableBH = DataTablesAjaxScrollHeight('#tableBaseHour', colsBaseLT, result.Grid, null, "350px");
        }
    });
}

In the first column, the Base Hour, I want there to be 12 pre-defined lines with the months of the year each. I’ve tried using the table.row.add, but as the Datatable is getting started by the Pagination method I ended up not being able to create the lines with the values I put.

Could someone help me with this?

EDIT: I managed to make Datatable show the list of Months, but it shows the whole list in one field! How do I make each month appear in a field of a different line?

inserir a descrição da imagem aqui

1 answer

1


 public DataTable Export(BMContext perRequestInstance){

        DataTable dt = new DataTable();
        dt.Columns.Add("Rule");

        return dt;
    }

I think it might help.

  • That’s exactly what my project needed, man, thank you very much!!!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.