<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('transacciones/grid','block=001')?>?' + s_url_param } );
        jQuery( '#jqGrid' ).trigger( 'reloadGrid' );
    }
    
    showView = function( i_Id )
    {
        $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'transacciones/viewdel', 'block=001&s_TipoProc=shw&i_Id=' )?>' + i_Id );
        $( '#dialog' ).dialog( 'open' );
    }
    
    deleteRow = function( i_Id )
    {
        $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'transacciones/viewdel', 'block=001&s_TipoProc=dlt&i_Id=' )?>' + i_Id );
        $( '#dialog' ).dialog( 'open' );
    }
    
    closeWindow = function( s_NameWin )
    {
        $( '#' + s_NameWin ).dialog( 'close' );
    }
</script>

<script>
    var s_Estado_Valores = { value: "A:Activo;I:Inactivo" };
    var s_Tipo_Valores = { value: "L:Litros;M:Masa;U:Unidad" };

    var jqGridContent = $( "#jqGrid" );
    jqGridContent.jqGrid
    (
        {
            url         : '<?=buildUrl( 'transacciones/index', '' )?>',
            mtype       : "POST",
            datatype    : "json",
            //editurl     : 'edicionData.php',                        
            colNames    : [ 'IdTransaccionCabeceraConcat', 'Transacción', 'Tipo Referencia', 'Documento Referencia', 'Fec Doc', 'Alm Org', 'Usu Reg', '' ],
            colModel    : 
                          [
                            { name: 'IdTransaccionCabeceraConcat',  width: 0,   align: 'center', hidden: true, hidedlg: false, editrules : { required: true }, key: true },
                            { name: 'IdTransaccion',                width: 90,  align: 'center', editable: true, sortable:  true },
                            { name: 'TipoDocumentoFiscalDesc',      width: 100, align: 'center', editable: true, sortable:  true },
                            { name: 'DocumentoRefFiscal',           width: 90,  align: 'center', editable: true, sortable:  true },
                            { name: 'FechaDocumentoPer',            width: 100, align: 'center', editable: true, sortable:  true },
                            { name: 'IdAlmacen',                    width: 90,  align: 'center', editable: true, sortable:  true },
                            { name: 'UsuarioCreacion',              width: 90,  align: 'center', editable: true, sortable: true },
                            
                            { name: 'details', width: 20, sortable: false, search: false, align: 'center',
                                formatter:function()
                                {
                                    return "<span style='cursor:pointer;' class='ui-icon ui-icon-document' title='Mostrar Transacción' onclick='showView( $(this).parent().parent()[0].id );'></span>"
                                }
                            }
                          ],
			viewrecords : true,
			height      : $( window ).height()-220, 
			width       : $( window ).width() - 20,
            //width       : 600,
            //autowidth   : true,
            sortable    : true,
            multiSort   : true,
            //width: null,
            shrinkToFit: false,
            emptyrecords: "No se Encontro registros",
            //height      : 480,
            rowNum      : 100,
            rownumbers  : true, // show row numbers
            //multiselect : true,//SELECCION MULTIPLE
            pager       : "#jqGridPager",
            //caption     : "Products / Category Primary Grid View"
            onCellSelect: function()
            {
            },
            beforeSelectRow: function ( rowid, e ) 
            {
            }
        }
    );

    $( "#jqGrid" ).jqGrid( 'bindKeys' );
    
    $( window ).on
    ( 
        "resize", 
        function () 
        {
            var newWidth = $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 20;
            if( newWidth <= 705 )
            {
                jqGridContent.jqGrid( "setGridWidth", newWidth, false );
            }
            else
            {
                jqGridContent.jqGrid( "setGridWidth", newWidth, true);
            }
        }
    );
    if( $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() <= 705 )
    {
        jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 5, false );
        //jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().height() - 270, false );
    }
    else
    {
        jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 5, true);
    }
    setTimeout( "findControl();", 500 );
</script>
<?=crearFuentePopupIframe( array( "div_id"=>"dialog", "iframe_id"=>"myIframe", "popup_title"=>"Resumen", "popup_width"=>"$( window ).width()-100", "popup_height"=>"420" ) )?>