kendo网格动态列

时间:2016-06-24 19:35:49

标签: javascript jquery asp.net-mvc kendo-grid

我在kendo中有一个网格,它是动态创建的,当创建一次列的标题时生成好,但是当我回来时,娱乐网格只让我进入第一列标题

function GenerarTabla() {   

    var fieldsDinamicos;
    var fieldDinamico;
    myList = [];
    fieldsdynamic = [];

    $('#ColumnasaMostrar option').each(function () {
        col = {};

        col.text = $(this).attr("nombrecolumna");
        col.operacion = $(this).val();

        col.tipodato = $(this).attr("tipodato");
        col.nombrefuncion = $(this).attr("nombrefuncion");
        myList.push(col);
        fieldsdynamic.push($(this).attr("nombrecolumna"));
    });



    var listaColumnas = fieldsdynamic.join(", ");
    var datos;
    url2 = urlServicio + '/DynamicService.svc/' + entidaddinamica + '?$select=' + listaColumnas;
    //$.getJSON(url2, function (data) {
    //    datos = data;
    //});
    var model = {

        fields: {
        }
    };
    // model.fields["Id"] = {  type: "number" };


    var columnasDinamicas = [];
    var columnasAgregadas = [];
    var fieldsDinamicos = [];
    $.each(myList, function (key, val) {
        if (val.operacion != "undefined") {
            columnasDinamicas.push({
                field: val.text,
                title: val.text,
                footerTemplate: val.nombrefuncion + ": #: " + val.operacion + " #"
            });
            tipodato = consultarTipoDato(val.tipodato)
            model.fields[val.text] = { type: tipodato };

            columnasAgregadas.push({ field: val.text, aggregate: val.operacion });
        } else {
            columnasDinamicas.push({
                field: val.text,
                title: val.text
            });
            tipodato = consultarTipoDato(val.tipodato)
            model.fields[val.text] = { type: tipodato };


        }

    })







    $("#gridkendo").kendoGrid({
        dataSource: {
            type: "odata",
            transport: {
                read: {
                    url: url2,
                    dataType: "json"
                }
            },
            schema: {
                data: function (data) {
                    return data.value;
                },
                total: function (data) {
                    return data['odata.count'];
                },
                model: model
            },

            aggregate: columnasAgregadas,
            pageSize: 10
            //serverPaging: true,
            //serverFiltering: true,
            //serverSorting: true
        },
        height: 430,
        filterable: false,
        sortable: false,
        pageable: true,
        columns: columnasDinamicas
    });



}

first created second created

0 个答案:

没有答案