Question about datatables design directions

Question about datatables design directions

JackDanielsJackDaniels Posts: 1Questions: 0Answers: 0
edited December 2014 in Free community support

I don't know if I should ask this here or in the github. I just want to ask about design decisions/future features that maybe implemented or already have been in 1.10. I'm still using a legacy version.

Issue 1: Numeric indexing of columns
This is a problem I'm running into a lot. Datatables seems to like having everything be numeric rather than associative (that is, name-based) by default. For instance, for simplicity I would love to refer to a column by name rather than its index (which to me is silly because that can get changed and flipped around and hidden). Are there any plans to make datatables function more associatively? I realize the limitation here is the assumption that each column is unique. But I don't think that's very difficult to do (in fact, I can't even really think of any scenario where one would want 2 copies of the same column name; that's just ambiguity). And I think the time savings both server and client side are big (especially for AJAX...) would be substantial. Right now I'm just having to create workarounds for this. As a coding style, key-based systems seem to be much easier to work with for me at least. Numeric indexing seems to create far more problems than it could ever solve.

table.fnSetColumnVis( curtabarr[key]['index'] , cookiearray[key] );

... Is kind of what I had to do in order to get some key-value mapping going on for column visibility to save to a cookie because datatables default state saving can't handle my initializations (nothing ends up being saved...). I basically have to build complex multidimensional arrays that save both the current positions and the keys of columns so that the cookie I have saved with column states knows what to turn off and on in case it moves around or changes.

Issue 2: Dynamic column names and easier AJAX integration.
This is technically an issue I've solved via recursive functions that destroy and rebuild the table when columns change. Basically I'm curious as to why everything returned from an AJAX source can't simply be in key-information format. Or perhaps just having the keys (column names) as an array of their own by default and then having each row be numerically indexed. I don't think this has been changed even in the latest version as far as I can tell. Every single AJAX initialization example I've seen appears to have the column values of the datatable hard-coded somewhere. I'd like to just create a PHP (or whatever) backend that gets the data in a specific format from a query and just feeds it to datatables, which then renders the data, but numeric indices and hard-coded columns throw all of this off. I've created a workaround (that involves a very complicated and annoying to work with AJAX call) that basically has to redo the dom instantiation of the table and then has datatables work its magic. Is there any specific reason for this? To me it seems like the data displayed client side would be at the mercy of the server anyway, so it would be very nice to just specify a source that knows everything that needs to be displayed, and then let datatables take care of the rest. I remember seeing a discussion in 2011 that I believe asked this very thing on this forums, but the designer believed that it was a fringe case.

Well I don't think it's a fringe case anymore considering AJAX integration on the web is booming. Any web site that wants to have a fluid frontend is using it. Furthermore I believe this creates unfavorable overlap of concerns. If the server provides all the data that should be displayed and the client side is simply in charge of rendering and user interaction, that's great. But right now, I have to either define the column names in with the client side logic (which means if I want to change the data displayed I have to worry about 2 sources of truth), or do a very complex AJAX function that destroys and rebuilds the table recursively. This is somewhat unfavorable but works.

(can't give any code here that's not too proprietary as an example)

I love this library. It's just sometimes (well more than sometimes) I feel like I'm fighting against it to integrate some features that I would like to, almost to the point where I would have to rewrite it (likely using AngularJS). Those two design decisions up there are the main culprits. I manage to come up with complex workarounds by digging through the API and doing dom hacks. Am I just approaching my design methodology with this library wrong? I'm about to start writing a class that would let me work with datatables the way I'd like to. At this rate it's going to be hacky, so I just decided to ask this on here before starting. I realize it's a wall of text because I type too fast and I'm not exactly expecting responses, but hey I can dream right?

This discussion has been closed.