defining column render with data-render
defining column render with data-render
smo
Posts: 3Questions: 1Answers: 0
I want to define the column.render property directly with HTML using HTML5, something like this:
<th data-name="Name" data-render="what should go here?">Name</th>
It works fine for property such as name (data-name for example here), but for render, I can't make it work. Is it possible, I'd like to be able a use function to create a link from the data source, like what's demonstrated in the sample here: http://datatables.net/reference/option/columns.render
This discussion has been closed.
Answers
Can't be done in the HTML directly.
Oh. Sad. Thanks for your answer (is there a list of what works and what doesn't work with data-* attributes)?
And is there anyway I can define an a/href link using declarative syntax like data-* attributes?
Why do you need to define these things in the DOM?
I'd like to focus on declarative syntax (html) for my columns, instead of javascript, just like I can do with the column name. This is because the HTML is generated, so it's easier for me to add information to the HTML than to the javascript.
That would take some work to do I think. If you can code into datatabes what the render options are, then you put an attribute into each header that matches the render option. Then, before you trigger datatables, you could loop through the headers, pull out the attributes that you need, stuff them into an array and then reference that array in the datatables config.
It might be ugly, but it might work.
What do you want to achieve with the render attribute? You can't define a function in HTML attributes, so you are left with the ability to simply use existing data - which you could do, but that seems a little redundant given that you could just use HTML5 data attributes for orthogonal data side-stepping the need to define a renderer altogether.
Allan
I am facing the same situation: generating HTML is much easier for me than JS.
Wouldn't it be possible to reference the function using window['myFunction'] ?
Possible - although DataTables would still currently see the string.
At the moment there isn't a way of doing exactly this I'm afraid. It is something I'm looking at for a future version though.
Allan