Clearing the ui-grid after a button is clicked

Is there a method to clear all content from a ui-grid including filters, data, and columns?

I want to reset the grid when a button is clicked in order to fetch new data with an HTTP request and display it using the same grid without refreshing the page.

I attempted to use $scope.gridOptions.length=0, but the data persists and upon making a new request, the new results are added to the existing ones.

Answer №1

If you want to clear a ui-grid dataset, you can do so by resetting it using any array method.

$scope.gridOptions.data= [];

To remove all filters and columns, you'll need to reinitialize the gridOptions object using an object literal syntax.

$scope.gridOptions= {};

Answer №2

Adjusting the size of the grid does not have any impact on the data. Here is a suggestion to try:

$scope.gridOptions.data = {};

Answer №3

The code snippet $scope.gridOptions.data = []; appears to be functional. However, it may not eliminate columns as desired. It only clears the rows while maintaining the columns intact.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method for displaying a table using a JSON array?

I have a JSON array that I want to display in a table using React boxes: [ { id: 1, color: "red", size: "small" }, { id: 2, color: "blue", size: "medium" }, { id: 3, color: "green", size: "large" }, { id: 4, color: "yellow" ...

Material UI Grid has a problem with inconsistent column width when using direction='column' and flexWrap='wrap' attribute combination

I'm a newcomer to React and Frontend development in general. Currently, I am working on setting up a MUI Grid that organizes items in columns which wrap around when necessary. So far, I've been able to accomplish this by adjusting the direction a ...

What is the reason for AngularJS not supporting xor operations?

<form name="businessFormAbout" ng-show="(businessFormAbout.$submitted)^(businessForm.$submitted)"> The console displays an error with this line: [$parse:lexerr] Lexer Error: Unexpected next character at columns 30-30 [^] in expression [(businessF ...

Exploring the world of asynchronous operations with React Hooks

Hello, I am a beginner when it comes to React and JavaScript. I could really use some assistance with two hooks that I have created: useSaveStorage and useGetStorage. The issue I am facing is that my app is supposed to receive data and save it into AsyncS ...

Choose particular ng-repeat elements to emphasize them in a different location

I am currently working with a list that is being parsed by an ng-repeat directive. The user has the ability to filter this list, which is functioning correctly. One particular feature I am trying to implement is highlighting the first item in the filtered ...

How much worth does an unfilled text input box hold?

I've been working on integrating a search feature and I'm having an issue with the functionality. Below is the code snippets for both HTML and JS: HTML <form> <input type="text" ng-model="searchVar" class="searchbox"> <in ...

Generate a fresh object if the values within the TypeScript object are identical

How can I filter an object to return a new object containing elements with the same values? For example: allValues = {"id1": 3, "id2": 4, "id3": 3} The desired output is: filteredValues = {"id1": 3, "id3": 3} This is because the keys "id1" and "id3" hav ...

What is the best way to set the width of a w2grid to 100%

Has anyone tried using w2grid before? I'm having trouble figuring out how to make it fill its container 100%. Here's the HTML snippet: <div id="a" style="width:100%"> <!-- top left container--> <div>This ...

Experience the power of live, real-time data-binding for date-time input with AngularFire in 3 different

Here is a simplified version of my code snippet: tr(ng-repeat='entry in ds3.entries | orderBy:orderByField:reverseSort | filter:query as results') td input.screen(type='datetime-local', ng-model='entry.date_recei ...

Passing a Value from Child to Parent Function in Meteor: A Complete Guide

I am trying to pass the value of a result from a child element to its parent element. Initially, I used Session.set and Session.get which worked fine but I realize that using Sessions globally is not considered good practice. So, I attempted to utilize rea ...

Is there a way to resolve this issue? (An error occurred: TypeError - res.json is not a valid function)

When attempting to add an object to my MongoDB database const response = await fetch("/api/contact", { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json", }, }); I encounter the error message ...

A guide on linking an object in strapi V4 to a React app

Recently in strapi v4, there was a change in the response API structure from an array to an object. When analyzing the response using Postman on my local strapi API and converting it into raw format with stringify, I noticed that the API response consists ...

Tips for sending a variable to control a particular panel within an accordion in Angular 2

I have a collection of ngbpanels that are dynamically created using ngFor. I need to expand or collapse a specific panel based on certain conditions, but the ID I provide for the panel is stored in a variable. The code does not recognize the panel ID when ...

What could be causing the recurring appearance of the success alert message in an AJAX call to a PHP script in this particular situation?

Below you will find two code blocks, each designed to handle an AJAX call to a PHP file upon clicking on a specific hyperlink: <script language="javascript" type="text/javascript"> $(".fixed").click(function(e) { var action_url1 = $(th ...

What is the most effective method for generating dial images through programming?

Currently, I am in the process of creating a website that makes use of variously sized and styled dials to indicate progress. The filled portion of the dial represents how close an item is to being 100% complete. I am seeking a universal solution that wil ...

Learn how to dynamically hide elements on your screen when resizing using AngularJS

I am a newcomer to angularjs and I have been trying to hide certain html elements when the body is resized without success. Below is my controller code. var app = angular.module('studentPage',[]); app.controller ('studentController&apo ...

The access token for Axios POST API in React is either missing, invalid, or has expired

To successfully upload an image to the server using Axios, I first need to obtain the apiKey and access_token, which I have managed to do and saved in localStorage. However, when attempting to upload an image, I encounter a "403" error message as indicated ...

Troubleshooting Node.js and Express: Adding to array leads to displaying "[object Object]"

As a newcomer to web development and currently enrolled in a course for it, I am in the process of creating a test web server before diving into my main project. In this test scenario, my goal is to extract the value from a text block and add it to a respo ...

Employing a factory for transferring information between controllers in AngularJS

I am working on passing longitude and latitude values using the Google Maps API from one controller to another. I am utilizing a factory to achieve this, but encountering issues with either sending the information to the factory or retrieving it from there ...

Node.js implementation for processing batches of data from the Youtube Data API

I'm looking to leverage the Youtube API for batch processing multiple video ids in a single request. Currently, I'm able to successfully make individual requests by appending the video id, request parameters, and API key to the following url: ? ...