目前我在kendo-ui网格上的asp.net mvc5项目中工作......
我想知道是否有可能在网格按钮所在的网格中制作动作链接或url.action ....
<script>
$(document).ready(function () {
var projectdata = "http://localhost:xxxx",
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
toolbar: ["create"],
scrollable: false,
sortable: true,
groupable: true,
columns: [
{ field: "Name", title: "Task Name", width: "170px" },
{ field: "Status", title: "Status", width: "110px" },
{ field: "IsActive", title: "Active", width: "50px" },
{ command: ["edit", "delete", "Setting", "Task"], title: " ", width: "150px" }
],
editable: "popup"
});
});
</script>
我必须改变&#34;设置&#34;在命令字段中,将动作链接或url.action放在那里。
答案 0 :(得分:3)
如果您使用的是asp.net mvc,为什么不使用剃刀代码?
这是一个例子,希望它有所帮助
@(Html.Kendo().Grid<YourObject>()
.Name("grid")
.TableHtmlAttributes(new { style = "min-height: 331px;" })
.ToolBar(t => t.Create())
.Columns(columns =>
{
columns.Template(@<text></text>).ClientTemplate("<div style=\"text-align:center\">" +
"<a href=\"" + Url.Action("Test", new { id = "#=Id#"}) + "\"><i style=\"padding-right: 8px;\" title=\"Setting\" class=\"fa fa-pencil fa-lg\"></i></a>" +
"</div>").Width(60).Title("");
columns.Bound(c=>c.Id).Hidden(true);
columns.Bound(c=>c.Name);
columns.Bound(c => c.Status);
columns.Bound(c => c.IsActive).ClientTemplate("<div style=\"text-align:center\">" +
"# if(Active) {#" +
"yes" +
"#} else {#" +
"no" +
"#}#" +
"</div>").Width(15);
})
.Sortable()
.Filterable()
.Pageable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(m => m.Id))
.Read(read => read.Action("Read", "YourObject"))
)
).Filterable()
)
答案 1 :(得分:2)
创建自定义命令模板:
String sentence = "";
StringBuilder sb = new StringBuilder(sentence.length());
Scanner input = new Scanner(System.in);
System.out.println("Enter a sentence: ");
sentence = input.nextLine();
/*
* \\s (match whitespace character)
* (<?g1> (named group with name g1)
* \\w{6,}) (match word of length 6) (end of g1)
* | (or)
* (?<g2> (named group with name g2)
* \\S+) (match any non-whitespace characters) (end of g2)
*/
Pattern pattern = Pattern.compile("\\s(?<g1>\\w{6,})|(?<g2>\\S+)");
Matcher matcher = pattern.matcher(sentence);
//check if the matcher found a match
while (matcher.find())
{
//get value from g1 group (null if not found)
String g1 = matcher.group("g1");
//get value from g2 group (null if not found)
String g2 = matcher.group("g2");
//if g1 is not null and is not an empty string
if (g1 != null && g1.length() > 0)
{
//get the first character of this word and upercase it then append it to the StringBuilder
sb.append(Character.toUpperCase(g1.charAt(0)));
//sanity check to stop us from getting IndexOutOfBoundsException
//check if g1 length is more than 1 and append the rest of the word to the StringBuilder
if(g1.length() > 1) sb.append(g1.substring(1, g1.length()));
//append a space
sb.append(" ");
}
//we only need to check if g2 is not null here
if (g2 != null)
{
//g2 is smaller than 5 characters so just append it to the StringBuilder
sb.append(g2);
//append a space
sb.append(" ");
}
}
System.out.println("Original Sentence: " + sentence);
System.out.println("Modified Sentence: " + sb.toString());
并将其添加为列的一部分
<script id="command-template" type="text/x-kendo-template">
<a class="k-button k-grid-even" href=" @Html.ActionLink("Setting", "Home", "ProjectContr", new { orderId = id },null)">Even</a>
</script>
知道这只有在代码是cshtml文件的一部分时才会起作用,因为需要解析它。如果链接分隔为js文件,链接将失败。