Welcome Guest, Not a member yet? Register   Sign In
Paginator
#1

[eluser]JonoB[/eluser]
The core pagination class is super easy to use, but didnt provide the flexibility and features that I was looking for. I wanted to be able to sort column headings, choose the page size, and more.

This class is based heavily on the CI 2.0 core Pagination Class. However, if you pass in the right parameters, it will hopefully work some magic for you and create a table with sortable headers, as well as selectable page sizes

Although the core Pagination class works off the offset param, this class uses the the page number and page size, as well as the sort order and sort direction.

For this to happen, the uri has to be constructed in a very specific order of:
/page_no/page_size/sort_by/sort_order. So, for example, products/index/2/25/code/desc
means that I want to show the 2nd page, 25 records, sorted by code, sorted in descending order

Note that this class does not yet work with query strings

Please excuse me if this doesnt meet all the CI coding requirements. I'm still getting used to the framework and MVC in general.

Any comments, suggestions, bug fixes are welcome.

Grab the latest version from https://github.com/JonoB/CI-Paginator
#2

[eluser]Carlton[/eluser]
Just wanted to say thanks for such a great library, works perfectly.

I was trying to return "->result_array()" from my model but it turns out this had to be "->result()"

Suprised there aren't more replies to this thread, maybe because the library works so well ;-)
#3

[eluser]JonoB[/eluser]
[quote author="Carlton" date="1313424209"]Just wanted to say thanks for such a great library, works perfectly.

I was trying to return "->result_array()" from my model but it turns out this had to be "->result()"

Suprised there aren't more replies to this thread, maybe because the library works so well ;-)[/quote]
You are welcome. I've actually made a lot of enhancements since then...will upload to BitBucket asap.
#4

[eluser]JonoB[/eluser]
I've put the repo on github now: https://github.com/JonoB/CI-Paginator

Apologies that some of the tab spacing is a bit out of whack...bitbucket seems to screw up the formatting for some reason.
#5

[eluser]Carlton[/eluser]
I noticed that you can do something like this to make a link to a particular link followed by an ID (from the DB)

Code:
$columns = array(
    array(
        'database' => 'DB_ID',
        'header' => ' '
        'text' => 'Edit',
        'sortable' => TRUE,
        'default_sort' => TRUE,
        'anchor_link' => 'admin/edit/',
        'anchor_field' => 'DB_ID'
    )
);

Is there functionality for something similar with a checkbox so I can end up with something like the following where my value "football" is coming from a database field?

Code:
<input type="checkbox" name="sports" value="football"  />

I'm thinking I will have to add some code to "create_table" function and check for some new parameters to be supplied in the column config array
#6

[eluser]JonoB[/eluser]
I've come up against a very similar issue as well. The way that I handled it was as follows:

1. Define your table headings as usual, with the checkbox heading something like this:

Code:
$columns = array(
  array(
    'header' => '<input name="checkbox-header" type="checkbox" id="checkbox-header">',  
    'sortable' => FALSE,
  ),
  //etc
);

2. As normal, set up your paginator config vars, and then initialise
Code:
$this->paginator->initialize($config);

3. Pass the following vars to your view:
Code:
$data['pagination']     = $this->paginator->create_links();
$data['page_sizes']     = $this->paginator->create_page_sizes();
$data['summary']        = $this->paginator->create_summary();
$data['table_headings'] = $this->paginator->create_table_headings();

4. Don't generate the table using the lib. Rather, generate your table manually, and pass the table records to the view:
Code:
$data['table_records']  = $this->Some_model->get_something(
    $this->paginator->sort_by, $this->paginator->sort_order, $this->paginator->offset, $this->paginator->page_size);

5. View
Code:
<table>
    <thead>
        <tr>
            <th>&lt;?php echo $table_headings[0] ?&gt;</th>
            <th>&lt;?php echo $table_headings[1] ?&gt;</th>
        </tr>
    </thead>
    <tbody>
    &lt;?php foreach ($table_records as $key => $row): ?&gt;
      <tr>
        <td>&lt;input type="checkbox" name="cid[]" value="' . &lt;?php echo $row-&gt;id; ?&gt; . '"/</td>
        <td>&lt;?php echo $row->something; ?&gt;</td>
      </tr>
    &lt;?php endforeach; ?&gt;
    </tbody>
</table>
#7

[eluser]Carlton[/eluser]
Thanks for the quick reply, I'll definitely be giving this a try
#8

[eluser]nl_vinyl[/eluser]
Does anybody have a simple example of how to implement this?

The Pagination setup I have now uses a model with two functions. One for counting the total amount of records and one for actually fetching the records with the limit and start that is being passed.




Theme © iAndrew 2016 - Forum software by © MyBB