Holt59 / datatable

Javascript Plugin for data tables creation
http://holt59.github.io/datatable/
MIT License
108 stars 42 forks source link

Destroy does not remove datatable #8

Closed FifthCloud closed 9 years ago

FifthCloud commented 9 years ago

Hello,

According to the documentation destroy is supposed to "Remove the datatable." However, I have found out that is not the case in my situation. I am uncertain as to how to remove the datatable once I have connected to it.

What I am doing is creating a search results and your paging system is a great tool and works wonders, but when a user wants to search something the datatable tool will not "forget" the previous entry no matter what I try. The results will always show whatever was first "inserted".

I will post the code on what I am doing and please correct me if I am using this tool in an incorrect manner. Any help would be greatly appreciated.

Code: for(var intRow = 1; intRow <= MaxRows; intRow++) { var rows = []; rows.push(rowArray[intRow][0]); // Cell 1 rows.push(rowArray[intRow][1]); // Cell 2 rows.push(rowArray[intRow][2]); // Cell 3 rows.push(rowArray[intRow][3]); // Cell 4 rows.push(rowArray[intRow][4]); // Cell 5 rows.push(rowArray[intRow][5]); // Cell 6 rows.push(rowArray[intRow][6]); // Cell 7 rows.push(rowArray[intRow][7]); // Cell 8 rows.push(rowArray[intRow][8]); // Cell 9 rows.push(rowArray[intRow][9]); // Cell 10 rows.push(rowArray[intRow][10]); // Cell 11 rows.push(rowArray[intRow][11]); // Cell 12 rows.push(rowArray[intRow][12]); // Cell 13 rows.push(rowArray[intRow][13]); // Cell 14 rows.push(rowArray[intRow][14]); // Cell 15 rows.push(rowArray[intRow][15]); // Cell 16 rows.push(rowArray[intRow][16]); // Cell 17

                tableData.push(rows);
            }
            try {
                if(jq1_11_1('#tblResults').datatable('select', 1) == null)
                {
                    jq1_11_1('#tblResults').datatable({pageSize: 50, destroy: null});
                                           //Also have tried with no success
                                           // jq1_11_1('#tblResults').datatable('destroy');
                }
            }
            catch(err) {
                                   // On the first time load there is no data.
            }
            //data: tableData,
            jq1_11_1('#tblResults').datatable({
                insert: tableData,
                pageSize: 50,
                sort: [true, true, true, true, true, true, true, true, true, true, false, true, true, false, false, true],
                filters: ['select', true, 'select', 'select', 'select', true, 'select', 'select', 'select', true, false, true, true, false, false, true],
                filterText: 'Type to filter... '
            }) ;

If I were to comment out the jquery calls using datatable no matter what was searched the results will correctly show.

What am I doing wrong? How do I tell the datatable tool to "forget" what I have inserted into it.

Thanks!

Holt59 commented 9 years ago

Hello,

If I understood you correctly, what you want to do is send a completely new set of data to the datatable?

Did you check the return value of jq1_11_1('#tblResults').datatable('select', 1) ?

When calling the datatable contrusctor, you should use « data » not « insert » to reset the current set of data - If you don't, the plugin uses the current values in the HTML table, which, in your case, are the old entries.

FifthCloud commented 9 years ago

Thank you for responding so soon. I did not want to search for another tool as this project I am working on is coming to a close. Your paging tool is sweet.

Your suggestion is exactly what I was going for. This is what I did per your recommendation.

Code: try { if(jq1_11_1('#tblResults').datatable('select', 1) == null) { jq1_11_1('#tblResults').datatable('destroy'); } //data: tableData, jq1_11_1('#tblResults').datatable({ data: tableData, pageSize: 50, sort: [true, true, true, true, true, true, true, true, true, true, false, true, true, false, false, true], filters: ['select', true, 'select', 'select', 'select', true, 'select', 'select', 'select', true, false, true, true, false, false, true], filterText: 'Type to filter... ' }) ; } catch(err) { jq1_11_1('#tblResults').datatable({ data: tableData, pageSize: 50, sort: [true, true, true, true, true, true, true, true, true, true, false, true, true, false, false, true], filters: ['select', true, 'select', 'select', 'select', true, 'select', 'select', 'select', true, false, true, true, false, false, true], filterText: 'Type to filter... ' }) ; }

If something exists within the select statement I then use the "destroy" command to make it seem like the results keeps "refreshing". It works wonderfully!

I am closing this issue as its fixed! Thanks again! Sweet tool.

Edit: I just realized something. I make it seem like this tool was actually broken, but I just want to clarify I didn't know what commands to use to get me what I needed. The paging tool works just fine. But if I may make a suggestion that the documentation could be updated a bit to say that destroy works well with data and not insert. That's all. Thanks again!