« first day  last day (14 days later) » 

5:41 AM
@Tushar hi again :-)
 
6:00 AM
Hey
Sorry, was busy yesterday
@AvinashRaj
 
cool..
is there anything, I have done wrongly on the above code?
 
Is the problem solved?
Checking...
 
I have an idea of implementing a global var for storing the Datattable object and whenever I got the resp from the server, I want the dt to redraw using
4
A: How to force Datatables to re-render or re-load static dat?

Gyrocode.comUse rows().invalidate() to invalidate data for all rows and draw() to redraw the table. Please note that 'data' in rows().invalidate('data') is required if you use Javascript data structure (with data or columns.render options). $('#your_table').DataTable() .rows().invalidate('data') .dra...

or
 
Inside getVehicles, this will be Window when called as getVehicles().
Is it not working?
 
oh, sorry.. getvehicles func is working properly..
onUpdate(vehicle: any) {
    let isUpdated: boolean;
    vehicle.type = (vehicle.type.key) ? vehicle.type.key : vehicle.type;
    for (let i = 0; i < this.vehicles.length; i++) {
      if (this.vehicles[i].key === vehicle.key) {
        this.vehicles[i] = vehicle;
        isUpdated = true;
        break;
      }
    }

    if (!isUpdated) {
      this.vehicles.push(vehicle);

    }
  }
see this onUpdate function would be called automatically when a child component emits a single vehicle data
 
6:08 AM
This should also work.
Provided this is correct
 
for create, isUpdated should be false..
so it would execute
this.vehicles.push(vehicle);
now, I want the dt to rerender.
If I change the code to something like
if (!isUpdated) {
      this.vehicles.push(vehicle);
    this.buildTable();
    }
it shows the newly inserted data but on clicking the dt next button , it automatically disappears
 
Inside buildTable, you're creating new DataTable. You just need to re-render it. You can use draw().
 
yeah.. I'm creating new table agaian and agian..
    table: any;

   renderTable() {
        if (this.table) {
          this.table.rows().invalidate('data')
          .draw(false);
        } else {
          this.buildTable();
        }
      }
buildTable() {
    let table: any = jQuery('#vehicles-datatable');
    if (table) {
      let settings: Object = {
        pagingType: 'full_numbers',
        retrieve: true,
        order: [[1, 'asc']],
        columnDefs: [
          { targets: [0, 7], sortable: false, searchable: false }
        ]
      };

      setTimeout(() => {
        table.DataTable(<DataTables.Settings>settings);
        this.table = table;
      });
    }
  }
if (!isUpdated) {
      this.vehicles.push(vehicle);
    this.renderTable();
    }
hope the above should work..
 
this.vehicles.push(vehicle); ==> vehicles => table
 
yeah, here is the html code.
<tbody>
              <tr *ngFor="let vehicle of vehicles">
                <td>
                  <img src="{{vehicle.image}}" style="width: 32px" *ngIf="vehicle.image">
                  <img src="assets/img/{{vehicle.type.key|lowercase}}-64x64.png" style="width: 32px" *ngIf="!vehicle.image">
                </td>
                <td>{{vehicle.vehicleId}}</td>
                <td>{{vehicle.trackerId}}</td>
Tried the above code but it's not working
vendor.bundle.js:4890 Uncaught Error: Error in ./VehiclesComponent class VehiclesComponent - inline template:79:0 caused by: this.table.draw is not a function
 
6:22 AM
Incorrect this.
 
table.row is not a func,.
 
Cache this. var self = this; outside function and use self inside it.
 
sorry, I can't get you..
like this,

let self = this;
renderTable{
   self.tbale =
}
 
Yes.
 
I think self var got automatically declared which is of type window
 
6:27 AM
Try other name like _this, that, etc.
 
ok..
it's not working
renderTable() {
    let _that = this;
    if (_that.table) {
      _that.table.draw( 'page' );
    } else {
      this.buildTable();
    }
  }
if we use like
 
let _that = this; should be outside of function.
 
that = this;
renderTable {
 
Yes
 
then we can access that only with this.
like this.that
inside renderTable func
this is the last bit of task assigned to me.. I have completed all except this.. Currently I'm serving the notice period.
Next week I'm gonna join in HCL..
 
6:48 AM
Great. Congrats!
Is it working?
 
thanks..
buildTable() {
    let table: any = jQuery('#vehicles-datatable');
    if (table) {
      let settings: Object = {
        pagingType: 'full_numbers',
        retrieve: true,
        order: [[1, 'asc']],
        columnDefs: [
          { targets: [0, 7], sortable: false, searchable: false }
        ]
      };

      setTimeout(() => {
        this.table = table.DataTable(<DataTables.Settings>settings);
      });
    }
  }

  renderTable() {
    if (this.table) {
      this.table.draw( 'page' );
this won't show any erro. but I said before, the newly added row got disappeared once I click the next button..
 
That means the data is not updated
 
but I already inserted the returned data into the vehicles list
 
When you click on Next button, it is showing old data.
 
yep..
 

« first day  last day (14 days later) »