Delete Variable data from a Device

The following shows how to implement HTML Canvas Widget to delete variable data in a time window in Dynamic Dashboards

  • Create the structure. Paste the following in the HTML Code Editor Tab:

<div>
    <p id="token"></p>
    <p id="selectedDeviceID"></p>
	<p id="selectedDeviceLabel"></p>
	<select id = "labels"></select>
	<form id="date-form">
		<label for="date1">Start date:</label>
		<input type="datetime-local" id="date1" name="date1" value="2023-01-01T00:00" required>
		<br>
		<label for="date2">End date:</label>
		<input type="datetime-local" id="date2" name="date2" value="2023-01-01T12:00" required>		
		<br>
		<button type="submit">Delete values</button>
	</form>
</div>
  • Paste the following in the CSS Code Editor Tab:

    body {
      font-family: Arial, sans-serif;
      max-width: 400px;
      margin: 0 auto;
      padding: 2rem;
    }
    
    form {
      display: flex;
      flex-direction: column;
    }
    
    label, input {
      margin-bottom: 1rem;
    }
    
    button {
      cursor: pointer;
      background-color: #0077cc;
      color: white;
      padding: 0.5rem 1rem;
      border: none;
      border-radius: 4px;
      font-size: 1rem;
      font-weight: bold;
    }
    
    button:hover {
      background-color: #005aa3;
    }

  • Paste the following in the Javascript Code Editor Tab:

The result is a Widget as shown below:

The user can use the dropdown menu to select a variable from the current device in the Dynamic Dashboard, then select a time windows using the date pickers. Upon clicking the Delete Values button, the data for that device's variable will in the time window selected will be deleted. Note that since Ubidots schedules asynchronous task, you might need to wait a few minutes to see the values deleted.

Last updated

Was this helpful?