I tried to figure out a lot but could not solve the issue.

I created a table as markup in form. How can I show this as datatables table?

//my data
$users = array
(
array('uid' => 1, 'first_name' => 'Indy', 'last_name' => 'Jones'),
array('uid' => 2, 'first_name' => 'Darth', 'last_name' => 'Vader'),
array('uid' => 3, 'first_name' => 'Super', 'last_name' => 'Man'),
);

//header
$header = array
(
'first_name' => t('First Name'),
'last_name' => t('Last Name'),
);

//rows
$options = array();
// Next, loop through the $users array
foreach($users as $user)
{
$options[$user['uid']] = array // each element of the array is keyed with the UID
(
'first_name' => $user['first_name'], // 'first_name' was the key used in the header
'last_name' => $user['last_name'], // 'last_Name' was the key used in the header
);
}

// created table here
$form['table2'] = array
(
'#type' => 'item',
'#markup' => theme('table', array('header' => $header, 'rows' => $options)),

);

This gives a reguler table and I want this to be sortable searchable filterable table.

Comments

duellj’s picture

Status: Active » Fixed

Try changing the theme call to:

theme('datatable', ...)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.