Syncfusion RichTextEditor ASP.Net MVC Format dropdown - rich-text-editor

Can someone please help me how can I change the contents of Formats dropdown in richtexteditor ej2 syncfusion?
At the moment, default values are: Paragraph, Code, Quotation, Heading 1 etc.
I want to remove the Code, Quotation and add a new custom Format called "My Paragraph".
I have gone through the documentation and apparently, it is not listed.
Help will be appreciated.
Here is what my current configuration is:
#Html.EJS().RichTextEditor("table").ToolbarSettings(e => e.Items((object)ViewBag.tools)).Value((string)ViewBag.value).QuickToolbarSettings(e => { e.Table((object)ViewBag.table); }).InsertImageSettings(new RichTextEditorImageSettings() { Path = "/Uploads/", SaveUrl = "/Home/Save" }).ShowCharCount(true).MaxLength(2000).Created("created").Render()
Controller method return configuration in viewbag
var tools = new
{
tooltipText = "Custom Tools",
template = "<button class='e-tbar-btn e-btn' tabindex='-1' id='custom_tbar' style='width:100%'><div class='e-tbar-btn-text rtecustomtool' style='font-weight: 500;'> Custom Tools</div></button>"
};
ViewBag.tools = new object[] {
"Bold", "Italic", "Underline", "StrikeThrough",
"FontColor", "BackgroundColor",
"LowerCase", "UpperCase", "|",
"Formats", "Alignments", "OrderedList", "UnorderedList",
"Outdent", "Indent", "CreateTable","|",
"CreateLink", "Image", "|", "ClearFormat", "Print",
"SourceCode", "FullScreen", tools,"|", "Undo", "Redo"
};
ViewBag.table = new[] {
"tableRows","tableColumns","tableCellVerticalAlign","tableCellHorizontalAlign","backgroundcolor"
};
ViewBag.value="";

You can modify the existing “format” option using Format property as shown below.
[View]
#Html.EJS().RichTextEditor("default").Format((object)ViewBag.types).ActionBegin("onBegin").Render()
<script>
function onBegin(e) {
alert(e.element.textContent + " is Selected");
}
</script>
[Controller]
public ActionResult Index()
{
object format1 = new { text = "Paragraph", value = "P" };
object format2 = new { text = "My Paragraph", value = "BlockQuote" };
object format3 = new { text = "Heading 1", value = "H1" };
object format4 = new { text = "Heading 2", value = "H2" };
ViewBag.types = new { width = "40px",
types = new[] { format1, format2, format3, format4 }
};
return View();
}
If the newly added item has any predefined format, you can mention that format in value. Else if you want to perform custom action, then you can get the selected item through actionBegin event of RTE and perform required action there. Now the items will be displayed in toolbar as shown below
Sample

Related

sapui5 odata value xml content pretty

I have to achive something like this with multiple types of icons and colors so not all the icons in the column should be like that it could be red-icon-status-error or green-icon-status-success in base of oData values.
here is my code:
var jsonModel = new sap.ui.model.json.JSONModel();
var Source;
var clr;
jsonModel.setData(oData);..
for (var i = 0; i < oData.results.length; i++) {
iconSource = oData.results[i].ST;
switch (iconSource) {
case 'E':
{
Source = "sap-icon://status-error";
clr = "red";
}
break;
case 'S':
{
Source = "sap-icon://status-completed";
clr = "green";
}
break;
default:
{
Source = "sap-icon://status-critical";
clr = "grey";
}
break;
}
var jsonModel = new sap.ui.model.json.JSONModel(); //set new json model
jsonModel.setData(oData);//set the json
var view = that.getView();//get view
}//i close the for loop
var exempletable = sap.ui.getCore().byId(view.createId('tableviewid'));
var statusLabel = new sap.m.Label();
statusLabel.setText("Stat");
var statusColumn = new sap.ui.table.Column({
label: statusLabel,
template: new sap.ui.core.Icon({
src : Source,
color : clr
}),
width: "40px"
});
exempletable.insertColumn(statusColumn, 0);//here insteed of 0 it should be something like 0+i?
exempletable.setModel(jsonModel);//set model
exempletable.bindRows("/results");//bind rows
exempletable.setVisibleRowCount(10);
exempletable.setEnableSelectAll(false);
exempletable.setSelectionMode(sap.ui.table.SelectionMode.SingleSelectMaster);
exempletable.setNavigationMode(sap.ui.table.NavigationMode.Scrollbar);
});
},
So to reasume how do I loop in order to achive what I want, It's my logic good?
Instead of creating a new table in the controller you should init the table in the corresponding view. In your table item template you can format the values with a formatter function.
For formatter function example, check out following link:
https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.tutorial.walkthrough.23/code
You first do the Model binding in the table and setup the desired property to use the formatter function, the logic of the state handling is defined in the formatter controller (e.g. returns some value for one case).
I'm aussuming you initiallized your model with a given model name and you have knowledge about sapui5 bindings
var oExampleItemTemplate = new sap.m.ColumnListItem("idexampletemplate", {
unread: false,
cells: [
new sap.m.StandardListItem({
// The code after the comma within the title brackets calls the formatter function
title: "{parts: [ {path: 'your_model_name>property_name'} ], formatter: '<resourceroot.path.to.formatter.class.convertValueIntoMaterialGroup'}",
description: "{your_model_name>property_name}",
adaptTitleSize: false,
iconInset: true
})
]
}),
The above code is written for a javascript view, the example for an xml view you can find in the link pasted above.
Best regards

How to set default value in Kendo DropDownList

I have a Kendo DropDownList, but strangely enough I can not set its initial value.
Html.Kendo().DropDownList()
.Name("PersonalCoachName")
.BindTo(new SelectList((List<string>)ViewData["coachResources"]))
.HtmlAttributes(new { style = "font-size:8pt;" })
ViewData["coachResources"] is a List of string type. Regardless I use
.BindTo(new SelectList((List<string>)ViewData["coachResources"], "Default"))
or
.SelectedIndex(3)
DropDownList does not change it value and only display the 1st value in the list. I need help on this. Thanks.
The value works only in jquery, not in html helper. So it works in Jquery like
var dropdownlist = $("#PersonalCoachName").data("kendoDropDownList");
dropdownlist.value(coachId);
dropdownlist.refresh();
Use the Value-method. See example code below.
#(Html.Kendo().DropDownList()
.Name("DropDownListName")
.DataTextField("Text")
.DataValueField("Value")
.BindTo(model.DropDownListItems)
.Value(model.Selected)
)
EDIT:
DropDownList needs to be bind to List<SelectListItem> and it can be initialized as seen below.
var items = new List<SelectListItem>
{
new SelectListItem { Text = "Item0", Value = "0" },
new SelectListItem { Text = "Item1", Value = "1" }
};
In addition, I would recommend to use MVVM to attach it to view.
public class DropDownViewModel
{
public String Selected;
public List<SelectListItem> DropDownListItems;
public DropDownViewModel(String selected, List<SelectListItem> dropDownListItems)
{
Selected = selected;
DropDownListItems = dropDownListItems;
}
}
Use the property 'index' while initializing the kendo combobox to set the Default value.
$("#fabric").kendoComboBox({
autoWidth: true,
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Cotton", value: "1" },
{ text: "Polyester", value: "2" },
{ text: "Cotton/Polyester", value: "3" },
{ text: "Rib Knit", value: "4" }
],
filter: "contains",
suggest: true,
index: 3
});
There are two ways to set default value when initializing a kendo dropdown list.
$("#yourdropdownlist").kendoDropDownList({
dataTextField: "valueName",
dataValueField: "valueCode",
dataSource: [
{ valueName: "A", valueCode: "0" },
{ valueName: "B", valueCode: "1" }
],
//Method 1 -set index
//index: 0
//Method 2 - set default value and text
value: "0",
text:"行政区划"
});
This was my dropdown:
#(Html.Kendo().DropDownList()
.HtmlAttributes(new { style = "width:95%", id = "customerSelection" })
.Name("customers-dropdown")
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model)
.OptionLabel("Select Customer...")
)
I wanted to select the default option "Select Customer..." upon some function. I was able to do this using following code:
var dropdownBox = $("#customerSelection").data("kendoDropDownList");
dropdownBox.text("");
dropdownBox.value("");

Kendo().ComboBox() in a template - how to set SelectedIndex

Have a grid-template with a kendo combobox in:
<script id="templateSample" type="text/kendo-tmpl">
#*Active holds the selected value*#
# alert(Active) # //
#(Html.Kendo().ComboBox()
.Name("ComboBoxSample")
.BindTo(new List<SelectListItem>()
{
new SelectListItem()
{
Value = "true",
Text = "Yes",
Selected = false,
},
new SelectListItem()
{
Value = "false",
Text = "No",
Selected = false,
}
})
.DataTextField("Text")
.DataValueField("Value")
.SelectedIndex(1)
.ToClientTemplate()
)
</script>
The template appears whenever a row is expanded (see http://demos.telerik.com/aspnet-mvc/grid/hierarchy).
I can't figure out how to set selected index with the item currently selected.
To set selected item, I can chose to use SelectListItem.Selected or Combobox.SelectedItem, but how to set a value from the item currently showing in the template ??
Thanks.
I have found a way to solve this problem using javascript.
Add an event to the grid:
.Events(e=>e.DetailInit("aftertemplateload"))
And the script:
function aftertemplateload(e) {
$("#ComboBoxSample" + e.data.Id).data("kendoComboBox").value(e.data.Active);
}
and remember to add the new id to the combobox:
#(Html.Kendo().ComboBox()
.Name("ComboBoxSample#=Id#")
.BindTo(new List<SelectListItem>()
{ etc...

How can I display an array model property as a list in my view?

I have this array property in my model and would like to see it in my view as a dropdown list. Here's the array property:
public string[] weekDays = new string[5] { "monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
public string[] WeekDays
{
get { return weekDays; }
}
I've look for hours with no simple explanation or examples. Please help.
You can use DropDownList() html helper.
Html.DropDownList("weekDays",
Model.WeekDays.Select(s => new SelectListItem { Text = s }))
If you want to read the selected value you can use DropDownListFor() helper.
Html.DropDownListFor(model => model.SelectedWeekDay, //a property to assign the value
Model.WeekDays.Select(s => new SelectListItem { Text = s, Value = s }))
Here's how I solved it.
#{
var wekdys = new Enrollment();
#Html.DropDownList("weekDays", wekdys.WeekDays.Select(s => new SelectListItem { Text = s.ToString(), Value = s.ToString() }))
}
this allows me to have a DropDownList outside of the foreach loop

Link to foreign key in JQGrid

I have designed my jqgrid viewmodel as follows,
public class DomainJQGrid
{
public JQGrid DomainsGrid { get; set; }
public DomainJQGrid()
{
DomainsGrid = new JQGrid
{
Columns = new List<JQGridColumn>()
{
new JQGridColumn
{
DataField = "DomainId",
PrimaryKey = true,
Editable = false,
HeaderText = "Domain ID",
Visible = false
},
new JQGridColumn
{
DataField = "ClientId",
Editable = false,
Width = 150,
HeaderText = "Client"
},
new JQGridColumn
{
DataField = "DomainName",
Editable = false,
Width = 150,
HeaderText = "Domain Name"
},
new JQGridColumn
{
DataField = "Registered",
Editable = true,
Width = 100,
DataFormatString = "{0:d}",
HeaderText = "Registered",
}
},
AutoWidth = true,
};
DomainsGrid.ToolBarSettings.ShowRefreshButton = true;
}
}
And I am binding the datasource to using my controller as follows.
return gridModel.DomainsGrid.DataBind(hmEntity.DomainProducts);
in the above model, instead of my ClientId, how can I bring ClientName from my Client table?
If I am understanding correctly, you'd like to be able to define a column that uses a property of an object property.
Assuming you have a property of type Client, named Client, you'd want to be able to do something like:
DataField = "Client.ClientName"
Unfortunately, that doesn't seem to work. There may be a different notation that can be used for this, but I couldn't find any documentation when I ran into this scenario.
For the sake of getting past the issue, and at the cost of dirtying up the model, I chose to add a property to support the grid. It's on my 'technical debt' list and am hoping to find a better solution when I pay that back.
If you want to suffer that same burden :), add this to your DomainProduct class (again, assuming you have a Client property):
[NotMapped]
public string ClientName
{
get { return Client == null ? "" : Client.ClientName; }
}
And then just use ClientName for the DataField value.

Resources