ChatGPT answer to potential forum question
ChatGPT answer to potential forum question
![Loren Maxwell](https://datatables.net/forums/uploads/userpics/907/nQU402M3AJ88T.jpg)
Just sharing this here out of interest.
I knew there was a way to list all the DataTables on a specific page but couldn't remember offhand how to do it.
Of course I thought immediately of turning to my favorite people here at the DataTables forum and asking, but having played around a little bit recently with ChatGPT I thought I'd see what answer it would give.
There are a couple of other forum posts showing some ChatGPT code, although I just had a relatively simple question.
I wasn't expecting much, so I was surprised . . .
Prompt:
How can I list all the DataTables in the console?
Response:
To list all the DataTables in the console, you'll need to use the programming language or framework you are working with. Since you haven't specified a particular technology, I'll provide a general approach using JavaScript in a web browser console.
Assuming you have an HTML page with DataTables initialized, here's how you can list them in the console:
Open your web browser (Chrome, Firefox, etc.).
Visit the web page that contains the DataTables you want to list.
Right-click on the page and select "Inspect" or press Ctrl+Shift+I (or Cmd+Option+I on macOS) to open the browser's developer tools.
In the developer tools, navigate to the "Console" tab.
Type the following JavaScript code snippet in the console and press Enter:
console.log($.fn.dataTable.tables());
This code utilizes the DataTables API and the $().DataTable()
function to retrieve all the initialized DataTables on the page. The $.fn.dataTable.tables()
function returns an array of DataTables objects.
After executing the code, you should see an array containing the DataTables objects printed in the console. Each object represents a DataTable that has been initialized on the page, and you can explore its properties and methods as needed.
Note: This approach assumes you are using jQuery and the DataTables plugin. If you are using a different technology or framework, the code snippet might vary slightly.
/ Response
Of course you wouldn't type the console.log( . . . );
in the console itself, but it did identify $.fn.dataTable.tables()
as what you would type otherwise.
In addition, I recently saw on Quora that in addition to answers from other users they give AI answers as well.
I suspect one day in the not too far future @allan might be able to add a feature like that to the support forum here to answer some of the quicker questions many people have.
This question has an accepted answers - jump to answer
Answers
That's impressive! Incredible that it managed to pick out the right method from just your prompt and all of the information that it has available in fact. I'm constantly amazed at just how good ChatGPT and generative AI is in general.
That said, there are a number of things wrong with what it said - the opening paragraph for example suggests you can use other frameworks or languages. That obviously isn't the case since DataTables is a Javascript library. You couldn't use C#!
Also it is wrong when it says it uses
$().DataTable()
and what that method does. But then is correct in the next line in that paragraph.I think if it cut out the "waffle" and just gave the answer, it might have a better chance of not providing wrong / redundant information.
There have been one or two posts from folk saying "this is ChatGPT generated code, how good is this" and then showing 20 odd lines, a good amount of which is no-op or otherwise redundant, but again gives the right answer in the return.
It is super impressive, and maybe it will replace me one day, but not quite yet
. I do wonder what a model trained on my posts would look like - probably it would just repeat "Provide a test case please"...!
I am interested in the idea of a DataTables specific / tweaked model!
Allan
Awww @allan -- you could never be replaced! :-)
I actually think AI will become like most of the previous technological advances we've fretted over -- there might be an uncomfortable transition for some who are directly affected, but it'll ultimately allow humans to shift their focus onto more important things.
On the answer itself -- I've noticed ChatGPT does a lot of waffling in general.
I have to think the creators are concerned with it giving incorrect or imperfect answers that are taken as authoritative and probably even more concerned with it giving offensive answers, so it goes out of the way to overexplain, generating the waffle.
But I was mainly shocked it even knew what I was referring to when I said "DataTables" and more shocked when it offered up the (mostly) correct code, at least enough that I could quickly use it and move on rather than continuing to look for the answer or wait for the forum to respond.
A straight Google search on the same prompt has a bunch of noise in the top ten results, and then after I ignore the irrelevant sites I still have to go through relevant ones to find the actual answer.
It was a great first step in finding the answer to a relatively straightforward question and could probably field a large portion of the common questions here.
I'm sure in time you'll be able to subscribe to a service to offer a model trained on a specific body of knowledge and have a prompt on the site for simple questions like the one I had!
Until then -- and even after -- we'll still love you @allan!