Articles in this section
Category / Section

How to display a table data after clicking Submit button?

2 mins read

You can display the DataGrid while clicking the submit button of a form. This can be achieved by displaying the DataGrid inside the form “submit” event and prevent the default submit action by using the “preventDefault” method.

This is explained in the following sample code. In which, while submitting the form the DataGrid has been assigned with the data based on the user input value of the form and displayed it.

HTML

<div class="content-wrapper">
    <div id="userinput">
        <form id="Gridform">
            <input type="text" class="e-input" id="multiplier" placeholder="Enter number 1-9" />
            <button id="submit">Submit</button>
        </form>
    </div>
    <div id="mtable" style="display:none">
        <button id="close">Close</button>
        <div id="Grid">
        </div>
    </div>
</div>

 

JS

var grid = new ej.grids.Grid({
   dataSource: data,
   columns: [
            { field: 'OrderID', headerText: 'Order ID', width: 120, textAlign: 'Right' },
            { field: 'EmployeeID', headerText: 'Employee ID', width: 150, textAlign: 'Right' },
            { field: 'Freight', width: 120, format: 'C2', textAlign: 'Right' },
            { field: 'ShipCountry', headerText: 'Ship Country', width: 150 }
        ]
});
grid.appendTo('#Grid');
 
document.getElementById("Gridform").addEventListener("submit", (e) => {
e.preventDefault();
  var value = parseInt(document.getElementById('multiplier').value, 10);
 
 // Filtering the data with user input value
  data = new ej.data.DataManager(window.hierarchyOrderdata).executeLocal(new ej.data.Query().where("EmployeeID", "equal", value).take(15));
 
  // Assigning to DataGrid
  grid.dataSource = data;
 
  document.getElementById("userinput").style.display = "none";
  document.getElementById("mtable").style.display = "";
  document.getElementById("Gridform").reset();
});
document.getElementById("close").addEventListener("click", (e)=>{
document.getElementById("mtable").style.display = "none";
document.getElementById("userinput").style.display = "";
});
 

 

Output

Before form submit:

Before form submit

On form submit:

After button submit table data displayed

Demo: https://stackblitz.com/edit/grid-on-submit-jnb5a4?file=index.js


Conclusion

I hope you enjoyed learning about how to display a table data after clicking Submit button of Form.

You can refer to our JavaScript Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
You can also explore our 
JavaScript Grid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied