Show XX entries via link instead of dropdown

Show XX entries via link instead of dropdown

trevoctrevoc Posts: 14Questions: 3Answers: 1

I've created a menu to toggle the visibility of columns. I'd like to use the same menu to allow users to display 10 or 20 or 30 rows etc... I need a link to target this instead of a select box.

with the visibility, I used the js example on the site with links that look like this.

<a class="toggle-vis" data-column="7">SrSysID</a>

Any way to do the same with the show 10 rows or 30 rows etc...

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin
    Answer ✓

    There is a plug-in that provides that feature available here. Alternatively, use page.len() if you want to use your own links.

    Allan

  • trevoctrevoc Posts: 14Questions: 3Answers: 1

    Thanks alan,

    API worked great, sorry for the elementary question, still diving into all your documentation and the API. I must say that as good as DataTables is, it's greatest strength is the documentation. Bravo.

    For those ending up here and liking specific examples, Here's how I used the API. The example on the API page uses anchor links which happen to be captured by my site for another purpose and don't play well.

    My links look like this:

    <a href="#" class="pagelength" row-length="10">Show 10 records</a>
    <a href="#" class="pagelength" row-length="10">Show 50 records</a>
    

    and my DT initialization has this added (well minus the first and last line of course, just added that to show that I've included it within the initial.):

    var table = $('#VOTERdirectory').DataTable( {
        $('a.pagelength').on( 'click', function (e) {
            e.preventDefault();
    
            // Get the row length from the row-length attribute on the links
            // Use the DT page.len API https://datatables.net/reference/api/page.len()
            table.page.len($(this).attr('row-length')).draw();
        });
    } );
    

    Thanks again alan.

    PS - How would I go about getting a quote on some work with datatables. I see the support options and credits, that's fine, but once purchased, how would one request how much it would cost in credits to perform work. Also, the majority of my requests would not be a priority in regards to time, but rather I wouldn't expect you to answer these types of questions in the forums.

    Regards

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    Hi,

    Is it with regard to custom development? I'm afraid that is not a service that I offer at the moment. Instead I'm trying to focus on adding and improving features in DataTables and Editor.

    Allan

  • trevoctrevoc Posts: 14Questions: 3Answers: 1
    edited November 2016

    No, completely relevant to DT's, would be to help speed my development along.

    An example might be a custom export link. Probably code you'd know pretty well already, or even just pointing us in the right direction like you've been doing. Just without the guilt I have for only spending $9.00

    Or maybe I could purchase the Enorme donation (don't need the link or logo) and just keep asking questions. I'm usually pretty good with a swift kick in the right direction. I can sometimes go off on crazy coding binges in the wrong direction only to find out it was as easy as your above API for example.

    Personally, I just feel a moral obligation to give you something if I keep asking questions, and I have a few of those.

    Priority Support doesn't necessarily describe my questions, as there isn't anything wrong essentially, and I don't need priority.

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    Heh - thank you :smile:. If you have a few examples of the sort of questions you might be posing, that would be great. The above one happened to be relatively straight forward because I'd already written a plug-in for that (I really must write it up on the blog sometime!).

    I should say also that the support aspect of DataTables is extremely useful for me to see how the software is being used, how it can be improved and where better documentation is required. I get a lot out of it (even if it does take a fair amount of time :smile:).

    Allan

  • trevoctrevoc Posts: 14Questions: 3Answers: 1

    The one I'm working on now is just exporting a single column of e-mail addresses to the clipboard. I use server side processing and assume that although the (page: all) setting is initialized it only works for non-server side. (This makes sense to me, although If I'm proven wrong I wouldn't be upset) :) Would be nice to return all filtered results without first having to make the show X rows large enough to hold the results.

    and I'm also wondering the best way to approach removing null values returned to clipboard.

    I essentially want a list of 1@email.com; 2@email.com; 3@email.com

    I was thinking about making the new line character the semi-colon, I think I remember reading the set new line separator in the docs somewhere, but I didn't find anything about ignoring null values.

    Your thoughts on the best direction to take with this would be great.

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    With server-side processing you can set the page length (page.len()) to -1. You need to make sure that whatever server-side processing script you are using will accept that as a page length and not apply the OFFSET and LIMIT to the query.

    Another option might be to not use DataTables directly for that, but rather make an Ajax request that will just get the list of e-mail addresses (with whatever filtering applied) and copy them to clipboard using execCommand (which is what Buttons' uses internally as well).

    Allan

This discussion has been closed.