HTML5 data-* is being ignored
HTML5 data-* is being ignored
Hey there,
I'm trying to to sort one of our tables based off of a prescribed value according to the contextual value of a row. So, for instance, row A may have a smaller amount listed in the Price field, but it is actually given a high data-sort value because it is a higher relative price to an item it is in relation to than row B which has a higher absolute amount in the Price field yet lower relatively.
Even if that doesn't make sense :), what's happening is that a value is assigned to the <td>'s data-sort attribute in order to sort according to that yet it's the actual fields value that is being sorted on.
I have a regular <!DOCTYPE html>
declaration, so I should be good to go w html5 usage and I have this in my initialization order: [[6, 'desc']]
Any help is appreciated!
This question has an accepted answers - jump to answer
Answers
Hi,
This example shows that HTML5 data-* attributes should be operating correctly, so in order to provide any help we would need to be able to see and debug your page. Could you provide a link please?
Allan
Hey Allan,
Yup, that's where I had been looking for reference.
Here's the debug info: http://debug.datatables.net/azaris
Thanks for the debug link - I think the issue is that you are specifying
columns.data
properties for a DOM sourced table. DataTables is seeing that you are specifying a custom data point and therefore not overriding it, under the assumption that it should only mess with default values and not custom ones which could do more harm than good.What you would need to do is something like:
i.e. tell it to read the attributes.
I haven't actually tested that code (edit as in for this specific case), but I think it should work... :-)
Allan
Ooo I see. That makes sense. We're defining the columns dynamically in order to define them for Select2 and readonly usage because of Editor integration.
Here's what I've got based on what you posted above:
I removed the
<a>
since it seemed contextually appropriate ('forums/...). No errors, but no luck. Am I misunderstanding?Gah, I should've thought a bit more before posting again :p
After establishing the Editor's fields, we then loop through the fields to assign to the actual DataTable initialization like so:
We then assign dtfields to
columns
.I updated it to add the
data
element like you posted above with modifications:And voila! Only one remaining question, it grouped them (score!) but items with a data-order of 5 come first, then 10, then 0. Is it because it's not ordering it as a number but as a string?
Hi,
Good to hear you are nearly there with it! You need to add the
type
option to your object as well, and point it also at the sort data, so the type detection can occur on that data, and thus numeric sorting will be run.I really need to look at why the forum is attempting to add auto links in the code blocks...
Allan
I'll be able to toy with this in a bit, but for conversation's sake I'll post my next question beforehand: I can have the sort data's
type
different than the actual column's display data, right?I'll look around to see how to point the type to the data-sort in particular and see if I can push this over the finish line. Thanks for the help thus far!
Yes - display, sort, filter and type can all be different data points, or they can overlap.
Allan
Hey Allan,
I'm back :)
The above worked and solved for the problem. It did have ramifications on my Editor set up, though.
I have a field that kicks into a select2 box on edit. I was receiving this error message:
So, I changed this:
to this:
It does away with the error message, thankfully, and changes the field to a select2 box. However, now the select2 plugin isn't working.
Can you help me connect the dots a bit better? Thanks!
Well that was fast :) Ends up it was due to a whole other, unrelated issue.
But...there is in fact a related problem. I'm getting the /tn/4 cryptic error on submit. Worse still, trying to use the debug bookmarklet to help figure things out gets this error:
An error occurred, likely due to a circular reference
Any tips?
In the JSON data that is being returned from the Editor Ajax submit, is it returning the
row
object in the same format that is used for the DataTables load.Allan
I'm guessing not. I'm not seeing anything awry, but I think that's due to being iffy in what to look for. The data is sent back per usual. The only difference now being how the table/editor is set up per the above sorting parameters.
More info!
Seems to be an issue at this point:
Toying with it at present, but wanted to update the thread w that relevant info.
I hate to be needy, Allan, but I'm still stumped on the above. Any insight or suggestion?
Sorry for the delay - did you look into what data is being returned by the server and ensuring that the
row
parameter has the same data structure as the data for the DataTable? You might need to userow().data()
in your console to see what the data structure is for a row, since if you are loading it form the DOM it might not be as simple as my Ajax loading examples.Allan
My turn to apologize for delay :p
Some of this will be repetitive, but for sake of full clarity I figured I'd work through the entirety of the problems/solutions:
So if I group things correctly then I get this error on click when I go to edit:
The event code is:
Quick context for above: items that we don't want the user to interact with are given a class of
.readonly
. Addingmy-cross
allows me to target that particular inline edit and have select2 appear successfully.Upon selection from select2 I get the /tn/4 error saying that the an unknown [object Object] is present.
Here's what a
row().data()
looks like:And the AJAX request returns this:
And, finally, I've got this on preEdit():
I think that's where the issue comes into play.
json.OfferVenIt
brings back282612
but data.offerItem is now expecting that (housed in thedisplay
property) plus a@data-sort
Will try to solve for that and report back.
And that does it! :)
Thanks a bunch for talking it out w me.
Best-