Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I use jqxGrid / iTextSharp export to PDF ?
I get data by 'json'.
How can ('jqxGridResult') export to PDF using iTextSharp?

What I have tried:

function GetTestReportResult()
{   
 $.ajax({
  type: "POST",   
    url: "wsMethodDbData.asmx/getData", 
   contentType: "application/json; charset=utf-8",
   data: "{}",
   dataType: "json",
   success: OnSuccess,
   error: function (type) 
   { 
     $('#jqxLoader').jqxLoader('close'); 
     $("#errMsg").text("ERROR!!" + type.responseText);
     $("#messageNotification").jqxNotification("open");
   }
  });
                
  function OnSuccess(response)
   {
       var items;                    
       items = response.d;
                    
       if(items.length == 0)
       {
         $("#errMsg").text("No Data");
         $("#messageNotification").jqxNotification("open");
       }
       else
       {
        $('#jqxTabs').show();
        $('#jqxExpDesc').show(); 
                    
        GenerateGrid(items);
      }
                    
      $('#jqxLoader').jqxLoader('close');         
   }
 }


function GenerateGrid(data)
{
     var source =
     {
        datatype: "json",
        datafields: [
            {name:'Data0',type:'string'},
            {name:'Data1',type:'string'}
        ],
        localdata: data
     };

     var localdataAdapter = new $.jqx.dataAdapter(source);

     $("#jqxGridResult").jqxGrid(
     {
        width: '99%',
        height: '400px',
        autoheight: true,
        source: localdataAdapter,
        pageable: false,
        autoheight: false,
        sortable: false,
        altrows: false,
        enabletooltips: false,
        editable: false,
        autorowheight: false,
        showgroupaggregates: false,
        showaggregates: false,
        groupable: false,
        showstatusbar: false,
        sortable: true,
        showfilterrow: false,
        filterable: true,
        selectionmode: 'multiplecellsextended',
        columns:
        [
            {
                text: '#', align: 'center', sortable: false, filterable: false, editable: false, groupable: false, draggable: false, resizable: false, datafield: null, columntype: 'number', width: 60,
                cellsrenderer: function (row, column, value)
                {
                      return "<div style='margin:4px;'>" + (value + 1) + "</div>";
                }
            },
            {text:"Data0",width:200,align:'center',datafield:"Data0"},
            {text:"Data1",width:200,align:'center',datafield:"Data1"}
        ],
        theme: 'fresh'
    });
}
Posted
Updated 21-May-20 22:39pm

1 solution

I think you're going to have to write a method to export your JSON data as a PDF Table - this may be a start point jQGrid PDF Export[^] ... this might also be useful json - JQGgrid- Comment générer un fichier pdf/excel à partir des données de la grille[^]
 
Share this answer
 
Comments
ChrisKWHsu 24-May-20 22:43pm    
thanks Garth.
My development Tool is VS2003, without MVC.
How can I export "$("#jqxGridResult").jqxGrid" to PDF ??
Garth J Lancaster 25-May-20 0:57am    
What - you want me to write it for you ? .. er, no - 1) if you're a student then you have to assume you lecturers are watching, and we wouldnt be doing you any favour by cheating for you, or 'the industry' a favour if you had to work with one of us in the future 2) if you're being paid to do this then you're in a better position than many, myself included, having been 'hibernated' thanks to Covid-19 ...

- looking at the first link I supplied, there was this

private static void ExportPDF<TSource>(IList<TSource> customerList,string[] columns, string filePath)
{
    Font headerFont = FontFactory.GetFont("Verdana", 10, Color.WHITE);
    Font rowfont = FontFactory.GetFont("Verdana", 10, Color.BLUE);
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.GetInstance(document, 
               new FileStream(filePath, FileMode.OpenOrCreate));
    document.Open();
    PdfPTable table = new PdfPTable(columns.Length);
    foreach (var column in columns)
    {
        PdfPCell cell = new PdfPCell(new Phrase(column, headerFont));
        cell.BackgroundColor = Color.BLACK;
        table.AddCell(cell);
    }
    
    foreach (var item in customerList)
    {
        foreach (var column in columns)
        {
            string value = item.GetType().GetProperty(column).GetValue(item).ToString();
            PdfPCell cell5 = new PdfPCell(new Phrase(value, rowfont));
            table.AddCell(cell5);
        } 
    }
    document.Add(table);
    document.Close();
}


that's a good start
ChrisKWHsu 25-May-20 1:51am    
Sorry, Garth.
you dont need to write it for me. I just ask the advise of experts.
I really appreciate your willingness to respond to my inquiries.
Sorry for the misunderstanding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900