AlphabetSearch unknown feature
AlphabetSearch unknown feature
![jdadwilson](https://datatables.net/forums/uploads/userpics/489/n6T4VGQGU7T42.jpg)
Integral to each of my dataTables is the alphabetSearch feature. I added the following to the global extend defaults...
layout: {
top1: 'alphabetSearch',
top2: 'paging',
bottom: 'info'
},
Doing causes a unknown feature error. There is obviously something that I am not doing but I have no clue. I copied the code directly from the three part instructions.
For a test example use this URL: https://www.trgrayson.org/cemeteries-dt
For a live example using dataTable v1 just remove the -dt from the above url.
Thanks in advance for all your help.
jdadwilson
Answers
The domain name isn't resolving for me I'm afraid. Is there a typo in it perhaps?
The error suggests that you aren't loading the AlphabetSearch Javascript file. Or perhaps it is an old one that is being loaded?
Allan
My bad... URL should be... https://www.txgrayson.org/cemeteries-dt
Looks like you are loading alphabet search library twice:
The second one is
1.0.0
which might not work with DT 2.0. Remove it to see if that fixes the problem. If not then tell us where to find the Datatables init code and where you are setting the defaults.Kevin
I moved the alphabet_Search-x.0 functions from the java_functions directory to the vendor directory on my local system but forgot to delete the file from the main site java_functions directory.
The DT init code is in the cemeteries-dt.js file.
The expand default code is at the bottom of the alphabet_Search-2.0.js file. Probably not the best place so add it. Any suggestions as to where.
This is the code for loading js files. It is a little complex given that I am upgrading a lot of modules to dT-2.0.
This error is showing in the browser's console.
Along with this alert.
I believe these two errors are caused by setting the defaults, ie:
Inside
alphabet_Search-2.0.js
before the alphabet search feature has completed initialization and has returned. Move that code to the top ofcemeteries-dt.js
so it executes after the alphabet search has initialized, for example:Using the browser's network inspector the JSON response has this for the row data:
But you have defined
columns.data
like this:They don't match. Possibly the URL is wrong and is fetching the wrong data.
Kevin
I moved the default code to the top of the cemeteries-dt.js file as suggested.
Still getting the same problem.
Is there a better place to include the expand defaults code? The purpose of the code is to establish defaults for the dataTables initialization. This site has 53 instances in 27 modules of dataTables. The code should be placed such that it is only needed once not in each of the 27 modules. Could it be placed in a file by itself and loaded after the datatables-2.0.js module but before the cemeteries-dt.js module?
As for the aaData vs the columns... The aaData is for the stats of the cemeteries which displays above the table and load after the page is loaded. Changing the top1 default to null make everything work fine.
jdadwilson
The defaults code needs to execute after datatables.js and alphabetSearch.js are loaded and before any of the Datatables requiring the default settings are initialized.
I built a simple test case:
https://live.datatables.net/giwezonu/1/edit
This fails with the same error. It seems the CDN link in the blog points to the 1.0.0 version.
I updated the test case to use the CDN for the 1.1.0 version:
And it works:
https://live.datatables.net/mutabape/1/edit
Try downloading the working CDN and loading it on your page.
@allan will need to update the blog docs.
Kevin
Alpha bar loads but all letters have 0 count.
I also made a new file for datatables-globals.js. Load order is...
This works fine.
jdadwilson
Still looking for a reason why the alphabetSearch letter count is zero for all letters...
txgrayson.org/cemeteries-dt
According to this thread you will need to use
this.api().alphabetSearch.recalc()
ininitComplete
. The problem is that the alphabetSearch plugin is initialized with the Datatable before the Ajax response fills the table.Using this in the console:
resolves the issue:
Kevin
Thanks, it works... but it does raise a question. Is the need for the recalc in the initComplete because of dataTables v2.0? I did not have to do this with v1.0.
The need is due to the timing of initializing the alphabetSearch before the Ajax response. There is no data in the Datatable when alphabetSaerch initializes because the asynchronous ajax response hasn't returned yet.
I built a test case with the old 1.0.0 alphabetSearch and DT 1.13.11 using ajax loaded data:
https://live.datatables.net/socirone/6/edit
The
initComplete
option is commented out. Due to ajax loaded data it shows 0 records for all letters. UncommentinitComplete
and you will see it work properly. For wexample:https://live.datatables.net/bogavuti/1/edit
Did your DT 1.x use HRMl or Javascript sourced data?
Kevin
Both versions use js.
You can see the difference in this URL...
txgrayson.org/cemeteries for v1 and
txgrayson.org/cemeteries-dt for v2.
Your v1 version has this
initComplete
function:That function calls
that.api().alphabetSearch.recalc();
:Kevin
So the question is... how do I change the function (and call) in the initComplete to work with dt 2.0? This is call code...
And this is the function...
This doesn't work given that the recalc is never done.
I have a similar function in the drawCallback area that does a hide/show depending on the recordsDisplay vs length values.
Thanks for all your help. It is greatly appreciated!!!
jdadwilson
Try this:
Its not guaranteed that the variable (![:smile: :smile:](https://datatables.net/forums/resources/emoji/smile.png)
oTable
) assignment of the Datatables initialization object is complete wheninitComplete
executes. It's like which comes first the chicken or the eggthis.api()
gives access to the Datatables API ininitComplete
.Kevin
That worked!!! I changed the function to...
I'll change the hide_pagingInfo function in the drawCallback area to see what happens there.
Thanks much!!
jdadwilson
Changes to the hide_pagingInfo function worked great also. You can see the results here...
txgrayson.org/cemeteries-dt
Select the letter 'T' and you will note that the paging info does not show. Select another letter (with a count > 16) or 'All' and the paging displays again.
This is probably a small issue, but an important one for the UI. It seems weird to display the paging info if there are fewer records than the lengthMenu number. Likewise if the recordTotal is less than the lengthMenu why display the Alpha bar.
Thanks much
jdadwilson
p.s. On to my next question. (see next post about globals)