Caption for the datatable

Caption for the datatable

laxmiparklaxmipark Posts: 22Questions: 8Answers: 0

$('#jquery_table').append('<caption style="caption-side: top-right">2017- Analysis</caption>');

This is how I have set now. I would like to set the caption dynamic. Can I do it using variable?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    I don't really understand what you mean I'm afraid. If you want to use a variable for the content you would do something like:

    $('#jquery_table').append('<caption style="caption-side: top-right">'+myVar+'</caption>');
    

    Allan

  • laxmiparklaxmipark Posts: 22Questions: 8Answers: 0

    I would like to have caption for the Datatable grid displayed. I would like that be dynamic
    How would I do that.

  • laxmiparklaxmipark Posts: 22Questions: 8Answers: 0

    Hi Allan, I don't see you any content in your answer

  • kthorngrenkthorngren Posts: 21,368Questions: 26Answers: 4,956

    Allan's answer shows how to use a variable. This is standard Javascript syntax. Just to add to his code:

    var myVar = "This is dynamic data";
    $('#jquery_table').append('<caption style="caption-side: top-right">'+myVar+'</caption>');
    

    Kevin

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Answer ✓

    I'm still not really understanding your question to be honest. Why not just add a caption element? Example: http://live.datatables.net/yufiyiko/1/edit .

    Allan

  • laxmiparklaxmipark Posts: 22Questions: 8Answers: 0

    How do you use the variable in the append syntax of the data table
    var myvar = "This is dynamic data"
    $('#jquery_table').append('<caption style="caption-side: top-right"> myvar</caption>');

  • kthorngrenkthorngren Posts: 21,368Questions: 26Answers: 4,956
    Answer ✓

    Take a close look at the differences in the string you have versus the one Allan provided:

    Allan's:
    '<caption style="caption-side: top-right">'+myVar+'</caption>'

    Yours:
    '<caption style="caption-side: top-right"> myvar</caption>'

    Allan's is multiple strings added together using +:

    '<caption style="caption-side: top-right">' +myVar+ '</caption>'

    If this is unclear then please see the "JavaScript String Operators" section of this doc:
    https://www.w3schools.com/js/js_operators.asp

    Kevin

  • laxmiparklaxmipark Posts: 22Questions: 8Answers: 0

    Thanks Kevin.
    I got it.

This discussion has been closed.