Jump to content

DataTable


Soma
 Share

Recommended Posts

It just occurred to me that it would be amazing to be able to use a datatable for repeaters.

I know it's certainly by no means a simple request, but it would definitely be neat and in some cases preferable when handling lots of repeaters or working with certain data types.

Just a thought.

  • Like 3
Link to comment
Share on other sites

Yep. I've run into a few scenarios where it's a bit distracting having the field and row headers repeat with every repeater item, plus when using it for tabular data it would be nice to use a datatable to more easily read down a column.



I guess really it's a request for a completely different module, but posted here since Soma seems to be a chunk of the way there by already having experience with these things :D

Link to comment
Share on other sites

@Pete - i've been using Diogo's custom admin pages to handle situations with a lot of data that I want to put into a custom table, using dataTables.js, so since this is the results of a selector, i would guess that you could show the repeater data in something like this...

post-136-0-96493600-1375055063_thumb.png

  • Like 6
Link to comment
Share on other sites

  • 3 weeks later...

here's how i setup the custom datatable page:

1.) make a folder in site/templates called admin-custom; inside that i have a css and js folder; in those folders i put all the scripts and stylesheets for datatable (dataTable.css, jquerydataTables.min.js, jquery.uniform.min.js);

2.) make a template in the templates folder, i called it admin-product-table.php; with this code:

<table class="table table-bordered" id="dyntable">
 					<colgroup>
                        <col class="con0" style="align: center; width: 4%" />
                        <col class="con1" />
                        <col class="con0" />
                        <col class="con1" />
                        <col class="con0" />
                        <col class="con1" />
                        <col class="con0" />
                        <col class="con1" />
                    </colgroup>
                    <thead>
                        <tr>
                          	<th class="head0 nosort"><input type="checkbox" class="checkall" /></th>
                            <th class="head1">Parent Product</th>
                            <th class="head0">Series</th>
                            <th class="head1">Part #</th>
                            <th class="head0">Room Cu. Ft.</th>
                            <th class="head1">Price Ea.</th>
                            <th class="head0">Missing</th>
                        </tr>
                    </thead>

<?php 
	$products = $pages->find('template=product-child,sort=title|series');
		foreach ($products as $product) { 
		?>

			<tr class="gradeX">
                          <td class="aligncenter"><span class="center"><input type="checkbox" /></span></td>
                            <td>
                            	<a href="<?php echo $config->urls->admin; ?>page/edit/?id=<?php echo $product->parent->id ?>" target="_blank">
				   <?php echo $product->parent->title ?>
                            	</a>
                            
                            </td>
                            <td><?php if($product->product_series) {echo $product->product_series;} else {echo 'n/a';} ?></td>
                            
                            <td>
                            	<a href="<?php echo $config->urls->admin; ?>page/edit/?id=<?php echo $product->id ?>" target="_blank">
									<?php echo $product->title ?>
                            	</a>
                            </td>
                            <td>
	                            <?php 
					if($product->roomsize_min && $product->roomsize_max) {echo $product->roomsize_min . '-' . $product->roomsize_max;} else echo 'n/a'; ?>
                            </td>

                            <td class="price">$<?php echo $product->product_price; ?></td>
                            <td>
	                            <?php
									if(!$product->speaker_sensitivity) {
										echo '<span style="color:lime">Sensitivity</span>';
									} ?>
                            </td>
                        </tr>

					<?php } ?>
					</tbody>
                </table>

<script>
$(document).ready(function(){

	// dynamic table
	if(jQuery('#dyntable').length > 0) {
		jQuery('#dyntable').dataTable({
			"sPaginationType": "full_numbers",
			"aaSortingFixed": [[0,'asc']],
			"fnDrawCallback": function(oSettings) {
				jQuery.uniform.update();
			}
		});
	}
});
	
</script>

3.) under the Admin page, create a child page called Products,  uses template "admin-products" (which will need the ACP_scripts_and_styles field), and uses alternate template filename of admin. Paste the links to the scripts and stylesheets into the ACP_scripts_and_styles field:

site/templates/admin-custom/css/dataTables.css
site/templates/admin-custom/js/jquery.dataTables.min.js
site/templates/admin-custom/js/jquery.uniform.min.js

some of how you set this up will depend on which version of PW you are on  – see the ACP documentation about that;

in my case i have a child page of Products called Products Table which uses the admin-product-table template;

hope that's not too confusing; it's pretty simple, but tricky to explain; most of it you can figure out from the ACP documentation..

  • Like 4
Link to comment
Share on other sites

  • 3 months later...

Hi,

I'm using this module, thanks Soma, I have customised it for a specific report for a client.

Everything is ok except I don't understand why in the ProcessDataTable.module under the section

// return markup for output

I have created a custom field called 'deposit_paid' that is a checkbox. I have the following code:

// deposit paid
            $depositPaid = $p->deposit_paid;
            if($depositPaid == 'checked') { $depositPaid = 'Yes'; } else { $depositPaid = 'No'; }
            $sOutput .= '"'.$depositPaid.'",';

But when the table is output the results are reversed in that fields that are checked are set to 'No' and fields that are not checked are set to 'Yes'. If I change

if($depositPaid != 'checked') 

I get the expected output. Maybe it's something simple I am missing (like a few brain cells!!).

post-564-0-74715700-1386154975_thumb.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...