Retrieve data from Gridview

Asked

Viewed 168 times

-1

I need a javascript function that brings the data filled in gridview and put in a lista , searching found the following function:

        function pegarDadosGrid(e) {
            var dados = e.component.getDataSource().items();
            $("input[name='myHiddenInput']").val(JSON.stringify(items));
        }

But I can’t tell if it’s working, there’s no way to put break point

How can I take data from a grid and put it into one variável using javascript

My grid:

            <div class="divGrid">
            @(Html.DevExtreme().DataGrid<ContatosViewModel>().ID("gridContainer")
                                            .ColumnAutoWidth(true)
                                            .Height(200)
                                            .Width(758)
                                            .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.Con_nome);
                                                columns.AddFor(m => m.Con_vinculo);
                                                columns.AddFor(m => m.Con_fone);
                                                columns.AddFor(m => m.Con_fax);
                                                columns.AddFor(m => m.Con_celular);
                                                columns.AddFor(m => m.Con_email);
                                            }).DataSource(AgenciaController.ListaContatos)
                                            .OnContentReady("pegarDadosGrid")
            )
        </div>

1 answer

1


In the Function you quoted you can put Debugger; to debug the js code.

 function pegarDadosGrid(e) {
            var dados = e.component.getDataSource().items();
            debugger; // quando vc chamar pegarDadosGrid, a execução deve parar aqui
            $("input[name='myHiddenInput']").val(JSON.stringify(dados)); // aqui deve ser dados em vez de items
        }
  • Thank you very much, it’s working, vllww

Browser other questions tagged

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