Mgallegos\LaravelJqgrid\Renders\JqGridRender::getJavascriptExportFunctionCode PHP Method

getJavascriptExportFunctionCode() protected method

Get exporter's javascript code.
protected getJavascriptExportFunctionCode ( string $exportFormat ) : void
$exportFormat string
return void
    protected function getJavascriptExportFunctionCode(string $exportFormat)
    {
        $code = 'jQuery("#' . $this->gridId . '").jqGrid("navButtonAdd", "#' . $this->options['pager'];
        $code .= '",{"id": "' . $this->gridId . ucfirst($exportFormat) . 'Button", "caption":"' . $this->exportButtonsOptions[$exportFormat . 'ButtonText'];
        $code .= '", "buttonicon":"' . $this->exportButtonsOptions[$exportFormat . 'Icon'];
        $code .= '", "onClickButton":function(){ ';
        $code .= '
			var headers = [], rows = [], row, cellCounter, postData, groupingView, sidx, sord;
			jQuery("#' . $this->gridId . 'Model").val(JSON.stringify(jQuery("#' . $this->gridId . '").getGridParam("colModel")));
			postData = jQuery("#' . $this->gridId . '").getGridParam("postData");
			if(postData["filters"] != undefined)
			{
				jQuery("#' . $this->gridId . 'Filters").val(postData["filters"]);
			}
		';
        $code .= '
		groupingView = jQuery("#' . $this->gridId . '").getGridParam("groupingView");
		sidx = jQuery("#' . $this->gridId . '").getGridParam("sortname");
		if(sidx == null) sidx = "";
		sord = jQuery("#' . $this->gridId . '").getGridParam("sortorder");
		if(sord == null) sord = "";
		if(groupingView.groupField.length > 0)
		{
			jQuery("#' . $this->gridId . 'Sidx").val(groupingView.groupField[0] + " " + groupingView.groupOrder[0] + "," + " " + sidx);
		}
		else
		{
			jQuery("#' . $this->gridId . 'Sidx").val(sidx);
		}
		jQuery("#' . $this->gridId . 'Sord").val(sord);
		';
        if ($this->jqPivot) {
            $code .= '
			jQuery.each($("#gbox_' . $this->gridId . '").find(".ui-jqgrid-sortable"), function( index, header )
			{
				headers.push(jQuery(header).text());
			});
			jQuery.each($("#gview_' . $this->gridId . '").find(".ui-widget-content"), function( index, gridRows )
			{
				row = {}, cellCounter = 0;
				jQuery.each($(gridRows).find("td"), function( index, cell)
				{
					row[headers[cellCounter++]] = $(cell).text();
				});
				for (i = cellCounter; i < headers.length; i++) {
						row[headers[i]] = "";
				}
				rows.push(row);
			});
			jQuery("#' . $this->gridId . 'Rows").val(JSON.stringify(rows));
			';
        }
        $code .= ' jQuery("#' . $this->gridId . 'ExportFormat").val("' . $exportFormat . '");';
        $code .= 'jQuery("#' . $this->gridId . 'ExportForm").submit();} });';
        if (!$this->exportButtonsOptions[$exportFormat . 'ButtonVisible']) {
            $code .= 'jQuery("#' . $this->gridId . ucfirst($exportFormat) . 'Button").hide();';
        } else {
            $this->exportButtonsVisible = TRUE;
        }
        return $code;
    }