Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
3 posts Page 1 of 1
DataTables.net can be fitted into CouchCMS backend. If you never tried datatables - don't miss on its awesome features - see link https://datatables.net

Adding to this post viewtopic.php?f=2&t=11126&p=29031#p29031, here are some tips.

Most customization can be done via config_list_view (feature of CouchCMS 2.0+ viewtopic.php?f=5&t=10241 ). -

Override default '1000'-pages limit of pages tag and set it to be big enough (or exact) to fit in all your cloned pages -
<cms:config_list_view limit="10000" >

In essence we want all cloned pages to be present in html before activating datatable (unlike in server-side processing). DTs are known to work very fast on thousands of pages, sourced by html, javascript or ajax json file and anything above 1k would require server-side processing to keep up.

Automatic setting of limit goes like this:
Code: Select all
<cms:set total_pages = "<cms:pages count_only='1' show_unpublished='1' show_future_entries='1' />" />
<cms:config_list_view limit=total_pages>


2018-08-25-002.png
datatable filtered
2018-08-25-002.png (49.67 KiB) Viewed 1815 times


3 buttons: Copy, CSV, PDF are meant to save listing to clipboard or a file (csv/pdf). Selector Show: "All" helps tailor number of visible pages in the list. Filter is a filter and pagination is activated automatically. Nothing is changed anywhere - neither in data nor in actions buttons. Plugin is configured to recognize CouchCMS default format of date: "Aug 25th 2018" - sorting by date will be natural thanks to renown Moment.js library.

Credits for beautiful datatable styling and fitting goes to Eugene Kopyov @ Limitless Kit Html Template and fitting DT into CouchCMS backend is done by me. If you have any questions or suggestions, feel free to PM me.
Someone asked for a "Select All" checkbox that will select absolutely all rows across all paginated pages. Well, datatable allows that with a custom button -
2018-08-25-003.png
select-deselect buttons
2018-08-25-003.png (38.73 KiB) Viewed 1810 times


Contact me for any further customizations.
@trendoman - another big thankyou for this one.

Just wondering if you can point me in the right direction here.

I'm trying to put a check in so that if the total number of pages exceeds a set limit then the list reverts to original couch style with pagination & explanatory message, otherwise list with dataTables.

currently i have:
Code: Select all
<?php require_once( './c/cms.php' ); ?>
<cms:template title='Contact Form Data' clonable='1' executable='0' order='15' parent='data' dynamic_folders='1'>
    <cms:no_cache />
    <!-- LIST VIEW    -->
    <cms:set form_contact_data_dt_max_pages = "<cms:get_field 'global_contact_form_dt_max_pages' masterpage='globals_sa.php' />" scope='global' />
    <cms:set form_contact_data_total_pages = "<cms:pages count_only='1' show_unpublished='1' show_future_entries='1' />" scope='global' />
    <cms:if form_contact_data_total_pages lt form_contact_data_dt_max_pages >
        <cms:config_list_view exclude="default-page-for-<cms:embed 'functions/string/get-clean-url.html' url=k_template_name ></cms:embed>" searchable='1' limit=form_contact_data_total_pages order='1110' >
            <cms:smart_embed 'datatables/list-view' />

        </cms:config_list_view>

        <!-- FORM VIEW    -->
        <cms:config_form_view>
            <cms:smart_embed 'datatables/form-view' />
        </cms:config_form_view>
    <cms:else />
        <cms:config_list_view exclude="default-page-for-<cms:embed 'functions/string/get-clean-url.html' url=k_template_name ></cms:embed>" searchable='1'>
            <cms:html>
                <h1>dt_max : <cms:show form_contact_data_dt_max_pages /></h1>
                <h1># pages: <cms:show form_contact_data_total_pages /></h1>
                <h1># pages1: <cms:pages count_only='1' show_unpublished='1' show_future_entries='1' /></h1>
                <h1>dt_max1 : <cms:get_field 'global_contact_form_dt_max_pages' masterpage='globals_sa.php' /></h1>
            </cms:html>
        </cms:config_list_view>
        <cms:config_form_view></cms:config_form_view>
    </cms:if>


Obviously at the moment I'm having to refresh the template in order for the <cms:if...> statement to work correctly.
Any ideas on
1 - how i might make this dynamic?
2 - why the variables set in the template with scope global are not available in the <cms:config_list_view...> tag?

Thanks for any insights you might be able to offer,
cheers, gwil
3 posts Page 1 of 1