what is the exact value for '#example' ?

what is the exact value for '#example' ?

bitsy1bitsy1 Posts: 6Questions: 1Answers: 0

Sorry for the beginners question, but I need to know so I can move on.

I have 2 tables (unpublished) so far. 1 and 2... table id=1 and table id=2

I'm adding extensions and imputing options into custom commands field. I'm using examples given on the support options page.

I would just like to know simply, what do I replace 'example' with? And will it be accompanied by the # and the hyphen?

Thank you

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited September 2015
    $(document).ready(function() {
        $('#your_choice_of_id').DataTable();
    } );
    
    <table id="your_choice_of_id" class="display" cellspacing="0" width="100%">
    

    What hyphen?

  • bitsy1bitsy1 Posts: 6Questions: 1Answers: 0

    Thank you tangerine,

    Just name it anything? I thought it would have to correspond to some number or name in the data table.

    the hyphens that enclose the #id like ' and '.

    Can you please confirm. I'm still not sure what to name it.

    thank you

  • bitsy1bitsy1 Posts: 6Questions: 1Answers: 0

    This is the code I'm using.

    Would this be correct?

    $('#put any random name here').DataTable( { responsive: true } );

    Thanks again

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Would this be correct? ... $('#put any random name here')

    No. Almost - but no. The $(...) part expects a jQuery selector. The # selector (per the jQuery documentation) is an id selector, so you would need to insert a valid element id and the spaces in the string to used above make it not valid (its a bit more complicated than that in actuality, but for simplicity, that is the case).

    I thought it would have to correspond to some number or name in the data table.

    It does - which is what tangerine suggested. You need to use the id of the element in the DOM. You are "selecting" the element that you wish to apply the DataTable to.

    It might be worth reading through a few jQuery tutorials to get to grips with selectors as it is core to how jQuery operates and DataTables is a plug-in for jQuery.

    Allan

  • bitsy1bitsy1 Posts: 6Questions: 1Answers: 0

    Thank You allen,

    I already did suspect that this was the case ( to use the id) . Also when I re-read tangerine's message a couple more times I finally got the idea he meant (id) and not any random thing that I choose. I mis-understood his reply at first.

    The short code in my table refers to the table as table id=2

    So would this be correct?

    $('#2').DataTable( { responsive: true } );

    If this is not correct, could you please give me a REAL example of what it should look like.

    Thank you

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    I gave you a real example. A jQuery selector - '#your_choice_of_id' - with a corresponding HTML table id -

    <table id="your_choice_of_id" ......>
    

    "your_choice_of_id" means, er, anything you like, as long as the jQuery usage matches the HTML usage.

    I can't make it any simpler. Do as Allan suggested and read up on the basics.

  • bitsy1bitsy1 Posts: 6Questions: 1Answers: 0

    I did read that page, it was very helpful. However, Your reply has further confused me.

    Allen said I need to insert a valid element id.

    I still do not understand how to use the id inside the bracket.

    short code - The table id=2

    Can you please tell me if this is correct.
    $('#2').DataTable( { responsive: true } );

    I understand I should use the id corresponding to the table. But how should it look inside the bracket???????

    I understand that this is a pesky question, but I need this answered so I can use this plug in correctly.

    Thank you

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    $('#2')
    

    provided that your HTML table has id="2".

  • bitsy1bitsy1 Posts: 6Questions: 1Answers: 0

    Thank you so much!

    I dare to ask, where can I confirm the html id?

    Only thing I see is the number in the list of tables as they were created, this also corresponds to the Short Code table id.

    Are those numbers considered the html id?

    thanks again

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    The HTML table tag, complete with id, is shown in the example in my first post.

This discussion has been closed.