title: How to sort a table in a pdf using itextsharp
body: <p>I am creating a table in PDF by using iTextsharp. I want to sort that table by its columns. </p>
  
  <p><img src="https://i.stack.imgur.com/lkW4o.jpg" alt="This is my output table">.</p>
  
  <p>When I click on first column it must be sort in alphabetical order,second column must sort in date wise order (Ascending order),and Third/fourth columns must sort in numbers order (Ascending order). Here is my code:</p>
  
  <pre><code>    public void createPdf(string filestream)
      {
  
          FileStream outputStream = new FileStream(filestream,      FileMode.Create,FileAccess.Write); 
          Document document = new Document(PageSize.A4);
          PdfWriter writer = PdfWriter.GetInstance(document, outputStream);
          document.Open();
          PdfPTable table = createtable();
          document.Add(table);
          document.Close();
  
      }
  
      public PdfPTable createtable()
      {
          PdfPTable table = new PdfPTable(4);
  
          float[] widths = new float[] { 2f, 1f,1f, 1f};
          table.SetTotalWidth(widths);
  
          PdfPCell cell;
          //First Row
          cell = new PdfPCell(new Phrase("Title"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("Date"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("Time"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("Year"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          //Second Row
          cell = new PdfPCell(new Phrase("The Counterfeiters"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("01/01/2007"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("09:30"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("2007"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          //Third Row
          cell = new PdfPCell(new Phrase("Requiem for a Dream"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("02/01/2000"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("11:30"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("2000"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          //Fourth Row
          cell = new PdfPCell(new Phrase("Cinema Paradiso"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("12/01/1988"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("20:00"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("1988"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          //Fifth Row
          cell = new PdfPCell(new Phrase("About Last Night"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("15/10/1986"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("27:00"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("1986"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          //Sixth Row
          cell = new PdfPCell(new Phrase("Sixteen Candles"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("11/09/1984"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("22:30"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          cell = new PdfPCell(new Phrase("1984"));
          cell.HorizontalAlignment = Element.ALIGN_CENTER;
          table.AddCell(cell);
  
          return table;
      }
  </code></pre>
  
  <p>I dont know any idea about how to implement this.   </p>