1

I have a number of "product nodes" that I'd like to return and display in a paged table.

The original query is generated as follows:

    $productNodeQuery = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('type', 'product', '=')
    ->extend('TableSort')
    ->extend('PagerDefault')
    ->limit($page_limit);

    $productNodes = $productNodeQuery->execute();

This returns all the products I want, however the pages are all messed up. Some pages have 3 items, some pages have 10, others have the full $page_limit (50) items per page.

I have a loop

foreach($productNodes as $productNode) {
....
}

to iterate over the results and add each product to the $rows[] array with this:

 $rows[] = array(
            'data' => array(
            'autoupdate' => $part['autoupdate'] == "1" ? 'ENABLED' : 'DISABLED',       // Display Checkbox?
            'part_number' => $part['part_number'],
            'title' => l($this_node->title, url($base_url . '/node/' . $this_node->nid)),
            'category' => l($this_category_name, url($base_url . '/catalog/' . str_replace(' ', '-', $this_category_name ))) . "<br />(Markup: " . $this_markup_percent['suggested_markup']*100 . "%)",
            'supplier_price' => $supplier_prices_string != "" ? $supplier_prices_string : "N/A",
            'suggested_price' => isset($suggested_prices_string) ? $suggested_prices_string : "N/A",
            'sell_price' => '$' . number_format($this_node->sell_price, 2),
            'competitors_price' => isset($competitor_prices_string) ? $competitor_prices_string : "N/A",
           'edit_node' => l('Edit Node', $edit_node_link, array('attributes' => array('target' => '_blank'))),
           'message' => "<em>" . $row_message . "</em>",
                ),
           'class' => array($row_class),
  );

Finally, after the $rows array has been defined with all the data I need I am building the table with this:

$form['table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => 'There are no product nodes found',
);
$form['pager'] = array(
    '#markup' => theme('pager')
);

Does anyone have an ideas as to where I'm going wrong with the pager?

(Full Form Code is available here: http://pastebin.com/bna1g1iV)

Thanks,

0

I would add this as a comment if I could. Looking at your code, it looks like you're only adding rows to $rows is $part['wtcr_sku'] is an empty string (line 258). It's possible you could be filtering out rows because of that.

| improve this answer | |
  • Thanks, I don't think that's the cause of it. The right items are getting added to the table, just instead of appearing on pages 1,2,3,... they are appearing on 20,21,22, with pages 1-19 being empty. – David Richardson Feb 24 '15 at 16:14
  • Have you tried building your $rows array without that if statement. I have a hunch you'll find that there are X number pages of data, but you're stripping out values based on your wtcr_sku values. Ideally, you would have that condition in your query so it would return the rows you actually want and the pager would count things correctly. Otherwise, you could manually build the pager yourself. – reallyxloco Feb 24 '15 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.