how to create module with table view and exposed filter

vj0914 - May 15, 2008 - 20:14

I am trying to build a customized module with table view, and also I want to have an exposed filter there. I am not sure how this can be done.

Can anyone help me out?

at least anyone knows how to

vj0914 - May 16, 2008 - 12:16

at least anyone knows how to display the content in table view,

http://drupal.org/node/206758 this tutorial shows content in list format, i wanna be able to show content in table format.

Is a custom module required?

Alan D. - May 16, 2008 - 14:59

Hi

Have you looked at views. These are very powerful and may do what you want already.

Failing that, the core table functions may help. Do a search for theme('table' for examples.

I cut this out of one of my own Drupal 6 projects. It creates a two column table with headers.

Use db_query instead of pager_query if you do not want pagination. Also drop $output .= theme('pager', NULL, 25);.

<?php

function citations_view() {
 
$header = array(
    array(
'data' => t('Tag')),
    array(
'data' => t('Citation')),
  );
 
$sql = "SELECT * FROM {citations} c";
 
$result = pager_query($sql, 25);
 
$rows = array();
  while (
$dblog = db_fetch_object($result)) {
   
$row = array('data' =>
      array(
       
$dblog->cid,
       
theme('citation_cs', $dblog)
      ),
    );
   
$rows[] = $row;
  }

  if (!
$rows) {
   
$rows[] = array(array('data' => t('No citations available.'), 'colspan' => 2));
  }

 
$output = theme('table', $header, $rows, array('id' => 'cid'));
 
$output .= theme('pager', NULL, 25);
  return
$output;
}

?>

Alan Davison
www.caignwebs.com.au

 
 

Drupal is a registered trademark of Dries Buytaert.