Comment activer jQgrid pour exporter des données au format PDF / Excel

Je suis nouveau dans le codage jQuery / jQgrid. J’utilise jQgrid version 4.4.4 & jQuery 1.8.3. Je souhaite activer la fonctionnalité d’exportation au format PDF / EXCEL dans mon jQgrid. Pour cela, j’ai mentionné les liens suivants – Cliquez ici et cliquez ici . Sur la base de ces liens, j’ai développé quelques lignes de code dans jquery qui sont les suivantes:

.jqGrid('navGrid', topPagerSelector, { edit: false, add: false, del: false, search: false, pdf: true}, {}, {}, {}, {} }).jqGrid('navButtonAdd',topPagerSelector,{ id:'ExportToPDF', caption:'', title:'Export To Pdf', onClickButton : function(e) { try { $("#tbPOIL").jqGrid('excelExport', { tag: 'pdf', url: sRelativePath + '/rpt/poil.aspx' }); } catch (e) { window.location = sRelativePath + '/rpt/poil.aspx&oper=pdf'; } }, buttonicon: 'ui-icon-print' }); 

Mais ce code ne fonctionne pas correctement. J’ai beaucoup cherché sur Internet, mais je ne reçois pas d’informations utiles et pertinentes pour accomplir ma tâche. Est-ce que quelqu’un sait comment faire ça ???

UPDATE: Je n’utilise pas la version payante de jqgrid.

fonction à appeler dans votre événement onclick.

 function exportGrid(){ mya = $("#" + table).getDataIDs(); // Get All IDs var data = $("#" + table).getRowData(mya[0]); // Get First row to get the // labels var colNames = new Array(); var ii = 0; for ( var i in data) { colNames[ii++] = i; } // capture col names var html = "" + "" + "" + ""; for ( var k = 0; k < colNames.length; k++) { html = html + "" + colNames[k] + ""; } html = html + ""; // Output header with end of line for (i = 0; i < mya.length; i++) { html = html + ""; data = $("#" + table).getRowData(mya[i]); // get each row for ( var j = 0; j < colNames.length; j++) { html = html + "" + data[colNames[j]] + ""; // output each Row as // tab delimited } html = html + ""; // output each row with end of line } html = html + ""; // end of line at the end alert(html); html = html.replace(/'/g, '''); // var form = "
"; // form = form + ""; // form = form + "

Si vous êtes sur PHP, essayez phpGrid . Ensuite, il vous suffit d’appeler

 $dg->enable_export('PDF'); // for excel: $dg->enable_export('EXCEL'); 

consultez http://phpgrid.com/example/export-datagrid-to-excel-or-html . Il génère le javascript jqGrid requirejs pour la grid de rendu.

Voici une solution astucieuse pour enregistrer les données jqGrid tant que feuille Excel: (il suffit d’appeler cette fonction avec GridID et un Filename facultatif)

 var createExcelFromGrid = function(gridID,filename) { var grid = $('#' + gridID); var rowIDList = grid.getDataIDs(); var row = grid.getRowData(rowIDList[0]); var colNames = []; var i = 0; for(var cName in row) { colNames[i++] = cName; // Capture Column Names } var html = ""; for(var j=0;j 

Nous créons d’abord une chaîne CSV délimitée par ; . Ensuite, une balise d' anchor est créée avec certains atsortingbuts. Enfin, click sur pour télécharger le fichier.

  if (exportexcel.Equals(excel) ) { GridView view = new GridView(); ssortingng conn = @"Server=localhost;port=3306;Database=jtext;Uid=root;Password=techsoft"; IFormatProvider culture = new System.Globalization.CultureInfo("fr-Fr", true); MySqlConnection con = new MySqlConnection(conn); con.Open(); MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataAdapter adp = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); view.DataSource = ds; view.DataBind(); con.Close(); HttpContext Context = HttpContext.Current; context.Response.Write(Environment.NewLine); context.Response.Write(Environment.NewLine); context.Response.Write(Environment.NewLine); DateTime ss = DateTime.Now; ssortingng custom = ss.ToSsortingng("dd-MM-yyyy"); ssortingng sss = DateTime.Now.ToSsortingng("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo); ssortingng aaa = "Generated Date and Time : " + custom + " " + sss; context.Response.Write(aaa); context.Response.Write(Environment.NewLine); foreach (DataColumn column in ds.Tables[0].Columns) { context.Response.Write(column.ColumnName + " ,"); } context.Response.Write(Environment.NewLine); foreach (DataRow row in ds.Tables[0].Rows) { for (int i = 0; i < ds.Tables[0].Columns.Count; i++) { context.Response.Write(row[i].ToString().Replace(" ", string.Empty).Replace(",", " ") + " ,"); } context.Response.Write(Environment.NewLine); } string attachment = "attachment; filename= " + rolefullname + ".xls"; context.Response.ContentType = "application/csv"; context.Response.AppendHeader("Content-Disposition", attachment); } } 

texte fort