alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.77k stars 361 forks source link

clear dynatable records before new update #168

Open nikhilkarmude opened 9 years ago

nikhilkarmude commented 9 years ago

I want to know how do I clear(remove all records) the table before I insert new records in table. Currently, the table is appending new records to the previous records.

My code: response = $.parseJSON(data);

            var dynatable = $('#printIDs').dynatable({
                dataset : {
                    records : response
                }
            }).data('dynatable');

             dynatable.settings.dataset.originalRecords = response;
             dynatable.process();
CaptainCannabis commented 9 years ago

take a look at this one

https://github.com/alfajango/jquery-dynatable/issues/162#issuecomment-65770248

nikhilkarmude commented 9 years ago

I looked over it, and tried many possibilities with the "settings" parameters but the new records seem to be appended to the older records. Is there any other work around?

CaptainCannabis commented 9 years ago

Are yout sure that "dynatable.process();" does what you expect it do to? Your are chaining the commands before so that var "dynatable" should contain the return value of ".data('dynatable')" - or am i completly wrong here?!

here are 2 functions that i am using in a project // function addRow(table,DS){

// bisher vorhandene DS
table.data('dynatable').settings.dataset.originalRecords.push(DS);

table.data('dynatable').process();

}

function delRow(table,DS){

var bis = table.data('dynatable').settings.dataset.originalRecords;
var neu = [];
$.map(bis,function(val, i){

    if(val.key != DS.key){
        neu.push({'key': val.key, text:val.text });
    }
})

table.data('dynatable').settings.dataset.originalRecords = neu;

table.data('dynatable').process();

}