Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mData property #20

Closed
fkurth opened this issue Dec 9, 2013 · 1 comment
Closed

Support mData property #20

fkurth opened this issue Dec 9, 2013 · 1 comment

Comments

@fkurth
Copy link

fkurth commented Dec 9, 2013

yadcf accesses column data by means of the column_number. If the dataTables option "mData" (1) is used, it may select the wrong data column.

Attached is a small patch to make it work.

diff -hu jquery.dataTables.yadcf.js.bak jquery.dataTables.yadcf.js 
--- jquery.dataTables.yadcf.js.bak  2013-12-09 07:56:31.000000000 +0100
+++ jquery.dataTables.yadcf.js  2013-12-09 09:09:47.197590393 +0100
@@ -602,6 +602,7 @@
            data,
            filter_container_id,
            column_number,
+           column_data,
            column_data_type,
            html_data_type,
            text_data_delimiter,
@@ -646,6 +647,10 @@
            data = args[i].data;
            filter_container_id = args[i].filter_container_id;
            column_number = args[i].column_number;
+           column_data = oTable.fnSettings().aoColumns[column_number].mData;
+           if (! column_data) {
+               column_data = column_number; 
+           }
            column_data_type = args[i].column_data_type;
            html_data_type = args[i].html_data_type;
            text_data_delimiter = args[i].text_data_delimiter;
@@ -702,7 +707,7 @@

                for (j = 0; j < data_length; j++) {
                    if (column_data_type === "html") {
-                       col_inner_elements = $(data[j][column_number]);
+                       col_inner_elements = $(data[j][column_data]);
                        for (k = 0; k < col_inner_elements.length; k++) {
                            switch (html_data_type) {
                            case "text":
@@ -722,7 +727,7 @@
                        }
                    } else if (column_data_type === "text") {
                        if (text_data_delimiter !== undefined) {
-                           col_inner_elements = data[j][column_number].split(text_data_delimiter);
+                           col_inner_elements = data[j][column_data].split(text_data_delimiter);
                            for (k = 0; k < col_inner_elements.length; k++) {
                                col_inner_data = col_inner_elements[k];
                                if (!(col_filter_array.hasOwnProperty(col_inner_data))) {
@@ -731,7 +736,7 @@
                                }
                            }
                        } else {
-                           col_inner_data = data[j][column_number];
+                           col_inner_data = data[j][column_data];
                            if (!(col_filter_array.hasOwnProperty(col_inner_data))) {
                                col_filter_array[col_inner_data] = col_inner_data;
                                options.push(col_inner_data);


(1) http://www.datatables.net/release-datatables/examples/ajax/deep.html

@vedmack
Copy link
Owner

vedmack commented Dec 18, 2013

Thanks , but your solution will won't work on a non mData datatable, because it seems that if you don't use mData explicitly it will be populated with column numbers , e.g for first column .mData is 0, for second .mData is 1 and so on... Anyway I did implemented the mData support and I did it for deep property reading from a data source too...
(Available in 0.5.0 version)

@vedmack vedmack closed this as completed Dec 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants