Create columns dynamically? #273

Open
dubcanada opened this Issue Feb 13, 2014 · 67 comments

Projects

None yet
@dubcanada

Hello,

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?

@DataTables
Owner

No I'm afraid not. There is no public API for adding or removing columns in DataTables 1.10. This is planned (although not 100% certain) for 1.11.

@DataTables DataTables added the 1.11 label Feb 13, 2014
@dubcanada

If I wanted to write such a thing because I need it. Do you have any ideas as to where I should start?

Is fnAddColumns not the correct place?

@DataTables
Owner

Yes, _fnAddColumn is the place to start there. Have a look at the constructor to see how DataTables uses it, and you'll want to look into the internal aoColumns array as well.

@w-diesel
w-diesel commented Jul 6, 2014

It seems that my problem related to this issue.
I have a lot of different ajax sourced tables, with different numbers of columns and "destroy" option didn't help to render additional columns.

@dubcanada Have you solved this problem? Please could you share your working example?)

@minohimself

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.

@w-diesel

@minohimself thnx for advise!
All features work? what about columns width?
Have you noticed any side effects?

@minohimself

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

@Misiu
Misiu commented Jul 29, 2014

@DataTables any chances we will see dynamic add/remove columns in near future?

@DataTables
Owner

Hi - unless this feature is sponsored, it isn't unlikely until 2015 as I'm working on other features at the moment and for the medium term future.

@rajington
  • 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.

@DataTables
Owner

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).

@rajington

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.

@Misiu
Misiu commented Jul 30, 2014

@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?

@w-diesel

@DataTables , as a option:

Create a community version of DT and provide the commit rights to the specific number of persons in that repository and develop commercial version of DT on the basis of community version.

This will help DT to develop faster, since to one person is very hard to control all commits, check them. and keep pace with competitors.


And, if Allan will go to Kickstarter i'll send him some RUS. Rubles 😄

@DataTables
Owner

Hi,

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.

@jods4
jods4 commented Sep 2, 2014

+1 that's a crucial feature for my use case as well. I'll try to work around it using destroy :(

@cdaringe
cdaringe commented Jan 9, 2015

👍

@shanonvl
shanonvl commented May 8, 2015

Hey there -- just wondering if there's been any movement on this issue? This is a key feature for my use case as well. Thank you!

@DataTables
Owner

No sorry. Likely won't be for a little with yet either as I'm working on other aspects of DataTables at the moment.

@jalousiescout-rodrigo

really looking forward to this feature :)

@temuri416

+1 for dynamic adding/removal of columns.

@doniking82

+1 for dynamic adding/removal of columns.

@escobar022

+1 for adding removing columns

@RiyaChauhan

+1 for dynamic adding/removal of columns

@paulodiogo

+1 for dynamic adding/removal of columns

@pchaganti

+1 for dynamic adding/removal of columns

@DataTables
Owner

This will happen - but there are other features / issues that I'm working on before it. There is no current timeline for when it might be implemented as it is a significant piece of work.

@ssy341
ssy341 commented Nov 6, 2015

+1 for dynamic adding/removal of columns

@mooncake-wong

+1 for dynamic adding/removal of columns

@iabdulin

+1

@danrcastro

+1 for dynamic adding/removal of columns

@garyee
garyee commented Dec 15, 2015

+1

@nordinebouti

+1 for dynamic adding/removal of columns, we really need it !

@StetsiukRoman

+1 for dynamic adding/removal of columns

@NetbearSoftware

+1 for dynamic adding/removal of columns. This would be amazing!

@gudladona87

+1 for dynamic adding/removal of columns

@ghprod
ghprod commented Jan 14, 2016

👍

@BaobabCoder

+1 for dynamic adding/removal of columns

@logzhouchen

+1 And thank you for your hard work

@djangosdk

+1 for dynamic adding/removal of columns

@MarcosBessega

+1 for dynamic adding/removal of columns

@rizkiandrianto

+1 for dynamic adding/removal of columns

@sday
sday commented Apr 6, 2016

+1 for dynamic adding/removal of columns

@doogthemushroom

+1 for dynamic adding/removal of columns

@SashkaCosmonaut

+1 for dynamic adding/removal of columns

@suensky
suensky commented Apr 29, 2016

+1 for dynamic adding/removal of columns

@michaelgavila

+1 :)

@windzzz
windzzz commented May 11, 2016

+1 for dynamic adding/removal of columns

@CloudyCity

+1 for dynamic adding/removal of columns

@jankill
jankill commented May 11, 2016

+for dynamic adding/removal of columns

@nkolban
nkolban commented May 11, 2016

+1 for dynamic adding/removal of columns

@temuri416

@DataTables

Why don't you start a small crowdfunding campaign? I suppose everyone on this thread would contribute $20, as this is such an important feature.

How about everyone here posting how much he's prepared to contribute to give Allan an idea?

  • $20 from me.

Cheers!

@dampee
dampee commented May 11, 2016

@temuri416 Great Idea! Count me in. I will need to discus the idea with my colleagues here. But $20 is a minimum.

@DataTables
Owner

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.

However, I'm not ignoring this!

@garyelephant

+1 for this

@tpegley
tpegley commented Jul 22, 2016

+1

@ssy341 ssy341 referenced this issue in ssy341/datatables-cn Aug 1, 2016
Closed

关于动态列的问题 #4

@guy032
guy032 commented Aug 4, 2016

anything new?

@saravan23

+1

@brentboden1

+1

@edgarfsilva

+1

@Thromshall

+1

@thanhpd
thanhpd commented Sep 30, 2016

+1

@JehadNasser

Hello datatable team,
waiting for this too.
thank you

@Indigo744

As the others, +1 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment