Рассчитан столбец фильтра сетки кендо - PullRequest
0 голосов
/ 17 сентября 2018

Привет, я оказываю поддержку клиенту, у которого есть приложение, разработанное на cakephp, и для сетки они использовали Kendo ui. У меня есть таблица в базе данных с столбцами «periodo», «nro_beneficio», «nombre», «cuil», «monto_haber» и «estado». А поля 'porcentaje' и 'monto_anterior' являются вычисляемыми полями. На сетке все поля отображаются нормально, но фильтр столбцов "porcentaje" и "monto_anterior" не работает. Можете ли вы сказать мне, что я делаю не так?

$(document).ready(function() {



    $("#ReportesHaberesPeriodo").kendoDatePicker({
        max: new Date(),
        format: 'MM/yyyy',
        start: 'year',
        depth: 'year'
        });

    //DataSource estados
    var dsEstados = new kendo.data.DataSource({
        transport: {
            read: {
                url: BASE_URL + '<?php echo $this->Html->url( array("controller" => "haberes", "action" => "estadoshaberes.json") ); ?>',
                dataType: 'json'
            }
        }
    });

    var dataSource = new kendo.data.DataSource({
        type: 'json',
        transport: {
            read: {
                url: BASE_URL + '<?php echo $this->Html->url( array("controller" => "reportes", "action" => "haberes.json") ); ?>',
                dataType: 'json'
            },
            destroy: {
                url: function( elem ) {
                    return kendo.format( BASE_URL + '<?php echo $this->Html->url( array("controller" => "haberes", "action" => "delete.json") ) . "/{0}"; ?>', elem.Haberespiloto.haber_piloto_detalle_id );
                },
             parameterMap: function(options, operation) {
                if (operation !== "read" && options.models) {
                    return {models: kendo.stringify(options.models)};
                    }
                },
                dataType: 'json',
                type: 'POST'
            }
        },
        filter: {field:'Haberespilotoscabecera.periodo', operator:'eq', value:'<?php if(isset($date)) echo $date; ?>'},
        error: function (a) {
            if( a.status == 'error' ){
                if( a.xhr.responseJSON )
                    stickErr(a.xhr.responseJSON.message );
                else
                    stickErr( a.errorThrown );
            }

            $('#haberes').data("kendoGrid").cancelChanges();
        },
        schema: {
            model: {
                id: 'haber_piloto_detalle_id',

                fields: {
                    periodo: {
                        from: 'Haberespilotoscabecera.periodo',
                        type: 'date'
                    },
                    nro_beneficio: {
                        from: 'Haberespiloto.nro_beneficio',
                        editable: false
                    },                      
                    nombre: {
                        from: 'Piloto.nombre',
                        editable: false
                    },
                    cuil: {
                        from: 'Piloto.cuil',
                        editable: false                 
                    },
                    monto_haber: {
                        from: 'Haberespiloto.monto_haber',
                        editable: false                 
                    },
                    estado: {
                        from: 'Haberespiloto.estado_importacion_haber_id',
                        editable: false         
                    },
                }
            },
            data: 'results',
            total: 'total'
        },
        batch: true,
        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,
        pageSize: 30
    });



    var wnd,detailsTemplate;

    var columns = [
    {
        field: 'Haberespiloto.nro_beneficio',
        title: '<?php echo __("Nro Beneficio"); ?>'
    },{
        field: 'Haberespiloto.numero_legajo',
        title: '<?php echo __("Legajo"); ?>',
        filterable: true
    },{
        field: 'Piloto.name',
        title: '<?php echo __("Nombre"); ?>'

    }/* ,{
        field: 'Haberespilotoscabecera.periodo',
        title: '<?php echo __("Periodo"); ?>',
        template: "#= kendo.toString(kendo.parseDate(Haberespilotoscabecera.periodo, 'yyyy-MM-dd'), 'MM/yyyy') #",
        format:'{0:yyyy MM}',
        filterable: {
                 ui: periodoFilter,
                 extra: false, 
                    operators: {
                        string: {
                            eq: '<?php echo __("Igual a"); ?>'
                        }
                    }
            }       

    } */ ,{
        field: 'Estadosimportacionhaberespiloto.nombre',
        title: '<?php echo __("Estado"); ?>',
        filterable: { 
                    ui: estadosFilter,
                    extra: false, 
                    operators: {
                        string: {
                            eq: '<?php echo __("Igual a"); ?>'
                        }
                    }
                }

    },{
        field: 'Haberespiloto.monto_haber',
        title: '<?php echo __("Monto"); ?>',
        template: '#= kendo.toString(kendo.parseFloat(Haberespiloto.monto_haber), "c") #',
        format: '{0:c}'

    },{
        field: 'monto_anterior',
        title: '<?php echo __("Monto Ant."); ?>',
        template: '#= kendo.toString(kendo.parseFloat(Haberespiloto.monto_anterior), "c") #',
        format: '{0:c}'

    },{
        field: 'porcentaje',
        title: '<?php echo __("Porcentaje"); ?>',
        template: '#= kendo.toString(kendo.parseFloat(Haberespiloto.porcentaje), "p") #',
        format: '{0:p}',
        filterable:

    },{
        field: 'Haberespilotoscabecera.tipo_cobranza_haber_id',
        title: '<?php echo __("Tipo Cobr"); ?>',
        template:'#:changeTemplate(Haberespilotoscabecera.tipo_cobranza_haber_id)#',
        filterable: {
                 ui: cobranzaFilter,
                 extra: false, 
                    operators: {
                        string: {
                            eq: '<?php echo __("Igual a"); ?>'
                        }
                    }
            }

    },{
        field: 'Haberespilotoscabecera.tipo_importacion_haber_piloto_id',
        title: '<?php echo __("Tipo Import"); ?>',
        template:'#:changeTemplate2(Haberespilotoscabecera.tipo_importacion_haber_piloto_id)#',
        filterable: {
                 ui: tipoFilter,
                 extra: false, 
                    operators: {
                        string: {
                            eq: '<?php echo __("Igual a"); ?>'
                        }
                    }
            }

    }];
    <?php if(isset($date)){ ?>      
    dataSource.filter([
    {
        "field":"Haberespilotoscabecera.periodo",
        "operator":"startswith",
        "value":"<?php if(isset($date)) echo $date; ?>"}
    ]);
    <?php }; ?>
    var delMsg = function(e) {
        return '<?php echo __("Esta seguro que desea eliminar el haber"); ?> ' + e.nombre + '?';
    }

    var _grid = fMakeCrudGridDetail( $('#haberes'), dataSource, '<?php echo __("Agregar haber"); ?>', delMsg, columns );


    function changeTemplate(value)
    {
        if (value == 1){
            return "LIST";
        }
        if (value == 2){
            return "CAPIT";
        }
    };

    function periodoFilter(element) {
                element.kendoDatePicker({
                    max: new Date(),
                    format: 'MM/yyyy',
                    start: 'year',
                    depth: 'year'
                });
            }


    //Filter: Estados
    function estadosFilter(element) {
        element.kendoDropDownList({
            dataTextField: 'Estadosimportacionhaberespiloto.nombre',
            dataValueField: 'Estadosimportacionhaberespiloto.nombre',
            dataSource: dsEstados,
            optionLabel: '--Seleccione--'
        });
    }

     $('#delete').on('click', function(e, item) {
        if (confirm('Seguro que desea eliminar los registros?')) {
               var grid = $('#haberes').data('kendoGrid');
               var arrAportes = {
                id: []
               };
               e.preventDefault();
               $('#haberes').prev('.alert').remove();

               if(!item){
                grid.select().each(function() {
                    var data = grid.dataItem( $(this) );
                    arrAportes.id.push(data.Haberespiloto.haber_piloto_detalle_id);
                });
               }else{ 
                    arrAportes.id.push(item);
                }
                kendo.ui.progress($('#haberes'), true);
               $.ajax({
                url: '<?php echo $this->Html->url(array('controller'=>'haberes','action'=>'delete')); ?>',
                type: 'POST',
                data: $.param(arrAportes)
               }).done(function(data) {
                    $('#haberes').before(data);
                    grid.dataSource.read();
                    grid.refresh();
                    kendo.ui.progress($('#haberes'), false);
                    });
             };
    });

    $('#findText').on('keyup', function(e) {
        var value = $(this).val();
        //if( e.which >= 48 && e.which <= 57 || e.which >= 65 && e.which <= 90 || e.which == 8 || e.which == 46 ) {
            if( value && value.length >= 3 ) {
                _grid.dataSource.filter({
                    logic: 'or',
                    custom: [{
                        field: 'Haberespilotossubdetalle.codigo_anses',
                        operator: 'startswith',
                        value: value
                    }]
                });
            } else {
                _grid.dataSource.filter({});
            }
        //}



    });

});
...