HTML5 data-* attribute for ajax url and dataSrc
HTML5 data-* attribute for ajax url and dataSrc
tstar
Posts: 36Questions: 0Answers: 0
Hello!
I cannot understand, how correctly define HTML5 data-ajax attribute for repeat this code:
ajax: {
url: "/blablabla",
dataSrc: ""
}
If I write data-ajax="/blablabla" - its work, but I need to define dataSrc also.
If I write data-ajax="{url: '/blablabla', dataSrc: ''}" - then I got Ajax error and very strange request from datatable: "GET /blablabla/%7B'url':%20'/blablabla',%20'dataSrc':%20''%7D?_=1438855845083"
Where am I making a mistake?
Thanking you in advance.
This discussion has been closed.
Replies
No you aren't making any mistakes. This looks like a limitation in the current implementation for these data attributes. Thanks for bringing it to my attention. I can't promise to have it fixed soon (I've got a large backlog!) but I have added it to my list.
Allan
Excuse me, it's still my fault. Everything works perfectly, if pass the right quoted parameters. Example:
You might also be able to do:
since it is valid for HTML attributes to use
'
as the quote.Interesting - I need to document that! Thanks for posting back.
Allan
The problem is that I also tried Your variant. I tried a lot of different options and only last worked. I understood when I wanted to add a parameter "columns".
Here was the exact same problem. I began to try various options for recording the attribute. After I wrote it as:
everything worked perfectly.
As a result, there is nothing wrong in this form of transmission parameters. In any case, for me it's not a problem. I use:
in my ASP.NET MVC project and get the desired result automatically.
Thanks for your work!
Sounds good - thanks for the feedback!
Allan
I have a problem again. Now I can not define a parameter "render" for columns. This should be an external function. In the code, I can write:
Please note that the attribute "render" has no double quotes around "Render.Test".
But the record in the attribute I can only record data-columns='[ {"data":"Test", "render": "Render.Test"} ]' which is equivalent to the code:
Note the double quotes around "Render.Test".
Maybe there's another way to pass function through the HTML5 data-* attribute?
Thank you for your help.
The problem is that JSON has no way to represent a Javascript function - so this simply will not work I'm afraid. This is exactly the reason why DataTables can't be configured by Ajax, only load data - it can't contain functions. You could use an
eval()
but it opens all sorts of security issues. Sorry.Allan
Also, we can not pass local variables via HTML5 data-* attributes. I understand that through the HTML5 data-* attributes and JSON we can send only text strings.
Probably it is necessary to highlight local variables by using special characters like "render": "[Render.Test]" or "render": "$Render.Test" and add the code to handle such cases. Then, setting the DataTables it can be fully implemented through HTML5 data-* attributes without a Javascript code.