How to display a table data after clicking Submit button?
This article explains how to display a table data after clicking Submit button.
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 is assigned with the data based on the user input value of the form and displayed.
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:
On form submit:
Refer to the working sample for additional details and implementation: Sample
Conclusion
We 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 forums, BoldDesk Support, or feedback portal. We are always happy to assist you!