Add Checkbox to Datagrid field

Asked

Viewed 78 times

2

I have a DataGrid and I’m wanting to put in a field a CheckBox, was researching and it seems that with the .EditorOptions() it is possible to do this, but do not know how, just passing CheckBox as parameter, n works, and I would like this field to send S or N for selected or not selected respectively

My code:

@(Html.DevExtreme().DataGrid<CobrancaViewModel>().ID("gridContainer")
    .ColumnAutoWidth(true)
    .Height(200)
    .Width(650)
    .ShowBorders(true)
    .Paging(paging => paging.Enabled(false))
    .Editing(editing =>
        {
            editing.Mode(DevExtreme.AspNet.Mvc.GridEditMode.Row);
            editing.AllowAdding(true);
            editing.AllowDeleting(true);
            editing.AllowUpdating(true);
    })
    .Columns(columns =>
        {
            columns.AddFor(m => m.CbaCob_carteira);
            columns.AddFor(m => m.CbaCob_variacao);
            columns.AddFor(m => m.CbaCob_especie);
            columns.AddFor(m => m.CbaCob_EspecieDocumento);
            columns.AddFor(m => m.CbaCob_Aceite);
            columns.AddFor(m => m.CbaCob_Aceite); //Gostaria de adicionar a essa coluna  o CheckBox                                                                                 
            columns.AddFor(m => m.CbaCob_convenio);
            columns.AddFor(m => m.CbaCob_SistemaCobranca);
            columns.AddFor(m => m.CbaCob_MensagemLocalPag);
    })
    .DataSource(AgenciaController.ListaContatos)
    .OnContentReady("pegarDadosGrid")
 ) 

For those who did not understand: I have a grid and several fields to be filled inside the grid, and I need one of these fields to be a selection field, example in the following image :

inserir a descrição da imagem aqui

  • what are the overloads of columns.AddFor()?

  • you want to show a Checkbox or S/N ?

  • I’m sorry, but I can’t answer that question

  • I want to show the Checkbox

  • when you write columns.AddFor(m => m.CbaCob_Aceite and adds a , it presents other constructors with more parameters?

  • Yes, I can even write Checkbox() But he says it’s not valid in context

Show 1 more comment

1 answer

0


I was able to solve it this way :

columns.AddFor(m => m.CbaCob_Aceite).DataType(GridColumnDataType.Boolean);

And I had a treatment at the controller:

foreach (var lista in ListaCobranca)
                {
                    lista.CbaCob_Aceite = lista.CbaCob_Aceite.Equals("true") ? "S" : "N";
} 

Browser other questions tagged

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