<table id="jqGrid"></table>
<div id="jqGridPager"></div>

<script>
    findControl = function ()
    {
        strFormSerialize = $( 'form' ).serialize();
        relaodGrid( strFormSerialize );
    }
    
    relaodGrid = function( s_url_param )
    {
        jQuery( '#jqGrid' ).jqGrid( 'clearGridData' );
        jQuery( '#jqGrid' ).jqGrid( 'setGridParam', { url: '<?=buildUrl( 'pro/gridPromo', '' )?>?' + s_url_param } );
        jQuery( '#jqGrid' ).trigger( 'reloadGrid' );
    }
</script>

<script>
    var s_Estado_Valores = { value: "A:Activo;I:Inactivo" };

    var jqGridContent = $( "#jqGrid" );
    jqGridContent.jqGrid
    (
        {
            url         : '<?=buildUrl('pro/gridPromo','')?>',
            mtype       : "POST",
            datatype    : "json",
            editurl     : 'edicionData.php',                        
            colNames    : [ 'IdPromoCab', 'Código', 'Descripcion', 'Cant', 'Precio', '' ],
            colModel    : 
                        [
                            { name: 'IdPromoCab',        width: 0, align: 'center', hidden: true, hidedlg: false, editrules : { required: true }, key: true },
                            { name: 'CodigoPromo',       width: ($( window ).width())/15, align: 'center', editable: true, sortable: true },
                            { name: 'DescripcionPromo',  width: ($( window ).width())/5, align: 'left', editable: true, sortable: true },
                            { name: 'SaldoDisponible',     width: ($( window ).width())/25, align: 'center', editable: true },
                            { name: 'PrecioConIGVPromo', width: ($( window ).width())/15, align: 'center', editable: true, formatter: 'currency', formatoptions: { prefix: 'S/. ', suffix: '', thousandsSeparator: ',' } },

                            { name: 'details', width: 20, sortable: false, search: false, align: 'center',
                                formatter:function()
                                {
                                    return "<span style='cursor:pointer;' class='ui-icon ui-icon-circle-triangle-e' title='Agregar Promocion' onclick='parent.asignarPromocionValores( $(this).parent().parent()[0].id );'></span>"
                                }
                            }
                        ],
            viewrecords : true,
            height      : $(window).height()-200, 
            width       : $(window).width() - 20,
            //width       : 600,
            //autowidth   : true,
            sortable    : true,
            multiSort   : true,
            //width: null,
            //shrinkToFit: false,
            emptyrecords: "Nothing to display",
            //height      : 480,
            rowNum      : 100,
            rownumbers  : true, // show row numbers
            //multiselect : true,//SELECCION MULTIPLE
            pager       : "#jqGridPager",
            //caption     : "Products / Category Primary Grid View"
            ondblClickRow: function( rowId, param2, param3, param4 ) 
            {
                //var s_UniMed      = param4.target.parentNode.children[2].innerHTML;
                //var s_Descripcion = param4.target.parentNode.children[7].innerHTML;
                //pr( "ondblClickRow -> " + s_UniMed + " - " + s_Descripcion );
                pr( arguments );
                pr( param4.target.parentNode.children[1].innerHTML );

                parent.asignarPromocionValores( param4.target.parentNode.children[1].innerHTML );
                //parent.asignarValores( rowId, s_Descripcion, s_UniMed );
            },
            onCellSelect: function()
            {
            },
            beforeSelectRow: function ( rowid, e ) 
            {
            }
        }
    );

    $( "#jqGrid" ).jqGrid( 'bindKeys' );
    
    $(window).on
    ( 
        "resize", 
        function () 
        {
            var newWidth = $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 20;
            jqGridContent.jqGrid( "setGridWidth", newWidth, true);
        }
    );
</script>

<?=crearFuentePopupIframe( array( "div_id"=>"dialog", "iframe_id"=>"myIframe", "popup_title"=>"Resumen", "popup_height"=>400, "modal"=>true ) )?>