Create columns dynamically?
#273

Assignees

Labels

Projects

Milestone

53 participants

With the new 1.10 is there the ability to create new columns dynamically? Say I have an ajax source, and I suddenly want to have 3 columns rather then the 2 I have when I initialized datatables, is there an easy way to do that?

I took a look and I saw _fnAddColumn but I was not sure if that is the properly place or what?

I have used a kind of workaround for this issue, i have different views with different columns/tables so what i did is i initialized my datatables with all distinct columns and then hide/show the appropriate ones.

You basically see all columns also those hidden so you have to make sure youre picking the right one other then that not maybe i bit animation would be cool :D, i will now try to link as some the data i show might by type hyperlink

For the sponsoring option, could you estimate the number of credits or the time it would take to do it the right way?

Would you be able to provide more examples of how to use the private _fnAddColumn in the short-term?

Alternatively, is destroying using the config's destroy option an okay interim solution?

Let's say a largish (a ~1000 array of objects, each with ~100 properties) dataset is managed completely using an external javascript variable and passed in using the data config option with a certain columns array. A new column is added to the columns array, so the table is initialized again with the same data, and (new) columns array, and destroy.

The documentation mentions adding data is "far more efficient" with rows.add, but I was wondering just how inefficient it is to destroy/recreate.

I get that the table might lose various setting such as page, order, filters, etc. but those could be managed separately. So far my tests seem to work fine, and I can post a punker for others if you think it's a good temporary workaround.

To do it fully and properly, including updating the extensions, I would estimate it would be around a weeks work (@8 hours a day, 5 days). That's a rough guess, but if you are interested in this option, I can certainly firm my ideas up and provide a quote offline.

Regarding _fnAddColumn - that was designed for use during initialisation only. It is not designed to add a column at any time and I doubt it could be done after initialisation without breaking other things.

The destroy option is basically the workaround for the moment. Destroy the table - manipulate the columns as you need and then create a new DataTable.

I was wondering just how inefficient it is to destroy/recreate.

Everything from the DOM needs to be read in again, so its really dependent on how big the data is, and the data source (if it is Ajax, obviously it will be quicker).

The data source would be a javascript object passed in data so maybe that's why I'm not getting much of a performance hit. I'm doing things in Angular so that does throw another wrench into things, I'll see if I can make my plunker more generic and then share that.

I understand about that quote I'll see if I can get funding approval for something of that magnitude, and thanks.

@DataTables@rikkert Maybe this can be done via Kickstarter or other similar platform?
Many of us would like to see this feature, but unfortunately I can't afford sponsoring full development because of studies, but I would love to give couple of dollars to help.
There are many users out there like me, so if everyone from community would give 1 dollar I think we might get this done 😄
What do You think guys? Do You know page when we could gather money to have this done?

Thanks for the suggestions - much appreciated! A community edition is certainly possible, although the software doesn't really feel "large" enough to warrant that just yet (my personal feeling about my little piece of software, so I might have the wrong perspective ;-) ). The community edition would also still need to be curated and the feature set kept inline with the pro edition, so it could potentially add extra work. However, accelerating the pace of development for the free software is certainly an attractive option.

Heh - thanks all for the feedback - much appreciated. This has to be the feature that has the most votes for inclusion :-).

I am fleshing out my plans for the next major update to DataTables just now and will look at exactly what would be required to include this. I suspect it would be a week or two of work. My problem at the moment is time - I'm spending about 60% of my time on support, so that 1-2 weeks becomes 2-5(ish) and there are other areas I feel I currently need to be working on.