Non Display of Alphabet Bar
Non Display of Alphabet Bar
Long time, big user of dataTables! (https://www.msholmes.org) Love the product!! I have 80+ instances of table use. Most are just 1 table on a page no problem. Some have 9000+ records and some just 3-15. Some can have <15 or >1000 depending on the initial search provided via an AJAX call. For those that can vary I wrote a few lines of code that checks the number of returned records against my Min standard of 15. If the returned number is less I hide the Alpha bar and also the Pagination info at the bottom. This works great for single tables on a page.
My latest new feature is to allow a site search that can create multiple tables on a page. Non display of the pagination works but non display the Alphabet string doesn't. The pagination, length, search areas all have unique IDs based on the name of the dataTable. But the Alphabet string ID is just myAlphabet.
Is this something that has been 'changed' in later versions? I'm still on 1.10.11. I tried 1.10.18 but the site blew up. Is there a work-around to the issue? Should I just change the DOM initialization for each to just exclude the items?
TIA for any assistance
jdadwilson
Answers
I might be missing something but what is the
Alpha bar
? Is it a builtin Datatable component or something custom?Do you have an example page we can look at to see what you are doing?
Do you have one of these for each table? If so the problem is likely that you have HTML elements with the same ID.
Is this independent of the
Alpha bar
? or is this what blew up?Kevin
The alpha bar (as I call it) is the area at the top of a table that has each of the letters of the alphabet that can be selected to filter the table.
It is a built-in dataTable component.
example: https://msholmes.org/cemeteries
I see, you are talking about utilizing the idea from the Alphabet Input Search blog. That is not a default Datatables component and is not controlled with
dom
or other Datatables initialization options. However you could hide thediv
that it is in with jQuery or other method if the number of rows is less than 15.Kevin
I think you missed the whole point of my question. Yes, when I have only one table on a page I can definitely hide the 'alpha bar' given that it has a unique ID of 'myAlphabet'. BUT when I have more than one table on a page the 'alpha bar' ID is then not unique and thus cannot be hidden if desired.
Not sure I understand what you mean when you say that the 'Alpha Bar' is not controlled with dataTables initialization options. What then is the purpose of the 'A' in the table dom: assignment? Doesn't this make it a default dataTables component?
p.s. I am not 'talking' about utilizing the idea from the blog. I presently have over 80 usages of a dataTable and each will show or hide the 'alpha bar' depending on the table length.
jdadwilson
https://datatables.net/reference/option/dom
There is no 'A' in the dom options. What gave you that idea?
You are adding the Alpha Bar as a
dom
plugin here in_site_functions.js
:This allows the use
A
in thedom
option as a plugin. This is explained in the Alpha Input Search - part III blog.You are creating the Alpha Bar here:
And assigning
id="myAlphabet"
. This is not something Datatables has control of. Based on your solution and code you will need to find a way to make this dynamic.Kevin
Been so long since I looked at the code I forgot it was there. Thanks.
My apologies. I wasn't aware of that feature.
kthorngren... I replaced Line 91 of the Blog III final code with the following
This then adds the table Id to the DOM. BUT... All of the 'letters' get the 'empty' class. Selecting a letter still works but all letters are gray. Any clue as to why? I'm at a loss.
TIA for any assistance.
jdadwilson
It looks like you are using a custom CSS file in the example you posted:
jquery.dataTables.myStyles.css
Which has:
Are you using the same for the page you are working on?
It would be hard to say without actually seeing it so we can see what styles are applied.
Kevin
Yes I do have a special css sheet for the tables. The styles work fine. The issue is that all the counts for each letter are zero which then causes the style for the letter to be 'empty'.
I copied your Alpha Search code from the example you posted. Replaced the same line with your two lines above and it seems to work. At least the letter counts work and the search functionality. The styling is no the same though.
Here is the example:
http://live.datatables.net/lijecira/1/edit
Without being able to see what you have it would be difficult to say why the counts are 0. Please post a link to your page or update my test case to replicate the issue.
Kevin
Kevin,
Can we take this discussion off-line. My email is... jamesawilson.ca@gmail.com.
Thanks.
If you want to provide a private link to your page please PM the developer @allan or @colin
Kevin
For you to see the result, I need to move the test scripts to the live site. Since the change causes ALL of the table to exhibit the same problem I don't want to leave it up any longer than necessary. Thus I would like to coordinate with you on a time frame that the switch could be made and then could change it back.
jdadwilson
Hi @jdadwilson ,
Another option would be to update Kevin's example so that it demonstrates the issue - would that be possible to do?
Cheers,
Colin