MVC: Replace the Ribbon Table Menu with a Quick Insert Table Drop-down
Replace the default Web.TextControl ribbon table button with a grid-based quick insert dropdown using JavaScript. The tutorial renders a visual row-and-column picker, sends the selected dimensions to an MVC controller, creates the table via ServerTextControl, and inserts it.

MS Word provides a quick insert table drop-down to insert tables into the document. This sample shows how to replace the insert table button with such a table insert drop-down.
The replacement and the new drop down button is done using Javascript and can be found in the GitHub repository. In order to insert the specific table, a controller method is called using Javascript:
function getTableFromController(cols, rows) {
var serviceURL = "/Home/GetTableFromController";
$.ajax({
type: "POST",
url: serviceURL,
contentType: 'application/json',
data: JSON.stringify({
Columns: cols,
Rows: rows
}),
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
TXTextControl.loadSelection(TXTextControl.streamType.InternalUnicodeFormat, data);
}
function errorFunc() {
alert('Error');
}
}
The controller method creates a new ServerTextControl instance to insert the specified table. The document is returned to the client and inserted at the current input position using the Javascript method loadSelection.
[HttpPost]
public string GetTableFromController(Table model)
{
byte[] data;
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Tables.Add(model.Rows, model.Columns);
tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}
return Convert.ToBase64String(data);
}
Download the sample from GitHub and test it on your own.
![]()
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2012 or better
- TX Text Control .NET Server (trial sufficient)
ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
MVC: Loading Files from the Backstage Menu
An MVC partial backstage view lists available files from a directory using a simple document model. When a user clicks a file, JavaScript sends an AJAX request to an HttpPost controller method…
MVC: Replace the File Menu with a Backstage View Menu
Replace the Web.TextControl File menu with a full-page backstage view using JavaScript and CSS. The tutorial disables the default FILE ribbon handler, renders a vertical navigation panel with…
MVC: Arrange a Docked Web.TextControl with a Custom Bar at the Top
Position a docked Web.TextControl below a custom toolbar bar in an MVC view by using CSS and JavaScript to offset the editor. The tutorial wraps the control in a DIV, sets absolute positioning…
MVC: Autosave and Restore Documents to and from the Local Browser Storage
Web.TextControl documents are autosaved to browser localStorage at five-second intervals using the JavaScript saveDocument method. On page reload, the ribbonTabsLoaded event checks for stored…
MVC: Loading and Saving Documents Through Controller HttpPost Methods
Web.TextControl X13 for ASP.NET MVC provides document load and save operations through controller HttpPost methods. The JavaScript API serializes documents as Base64, posts them via jQuery AJAX to…
