<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( 'oc/provGrid' )?>?' + s_url_param } );
        jQuery( '#jqGrid' ).trigger( 'reloadGrid' );
    }
    agregarDetalle = function( rowId, s_Descripcion, Contacto )
    {
        parent.asignarProveedor( rowId, s_Descripcion, Contacto );
        parent.$( '#dialog' ).dialog( 'close' );
    }
</script>
<script>
    var jqGridContent = $( "#jqGrid" );
    jqGridContent.jqGrid
    (
        {
            url         : '<?=buildUrl( 'oc/nothing' )?>',
            mtype       : "POST",
            datatype    : "json",
            colNames    : [ 'IdPersona', 'Codigo', 'Descripción', 'Contacto', 'Nacionalidad', '' ],
            colModel    : 
                          [
                            { name: 'IdPersona',            width: 0, align: 'center', hidden: true, hidedlg: false, editrules : { required: true }, key: true },
                            { name: 'IdPersona',            width: 80, align: 'center', editable: false, sortable: false },
                            { name: 'NombreCompletoLLeno',  width: 210, align: 'left', editable: false, sortable: false },
                            { name: 'Contacto',             width: 90, align: 'left', editable: false, sortable: false },
                            { name: 'NacionalidadDesc',     width: 90, align: 'left', editable: false, sortable: false },
                            { name: 'agree',                width: 35, align: 'center', sortable: false, search: false, 
                                formatter:function()
                                {
                                    var o_Data = arguments[2];
                                    return "<span style='cursor:pointer; margin: 0 auto;' class='ui-icon ui-icon-circle-triangle-e' title='Agregar Item' onclick='agregarDetalle( $(this).parent().parent()[0].id, $(this).parent().parent()[0].cells[3].innerHTML, $(this).parent().parent()[0].cells[4].innerText );'></span>"
                                }
                            }
                          ],
			viewrecords : true,
			height      : $(window).height()-150, 
			width       : $(window).width() - 10,
            shrinkToFit : false,
            sortable    : false,
            multiSort   : false,
            emptyrecords: "No se encontro registros",
            rowNum      : 100,
            rownumbers  : true, // show row numbers
            pager       : "#jqGridPager",
            shrinkToFit : false,
            ondblClickRow: function( rowId, param2, param3, param4 ) 
            {
                var s_Descripcion = param4.target.parentNode.children[3].innerHTML;
                var s_Contacto = param4.target.parentNode.children[5].innerHTML;
                agregarDetalle( rowId, s_Descripcion, s_Contacto );
            }
        }
    );
    
    $( "#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
    (
        function()
        {
            findControl();
            $( "#jqGrid" ).parents( 'div.ui-jqgrid-bdiv' ).css( "height", ($(window).height()-150) );
        },
        300
    );
</script>