简体   繁体   English

kendo ui:如何进行默认排序,电话号码格式设置以及将单词null替换为none

[英]kendo ui: how to do default sorting, phone number formatting and replace the word null to none

in my code, i want to do the gird table with default sorting by last name ascending, phone number formatting with (xxx)-xxx-xxxx and replace the word null to none,for example some mobiel number is null, i want to display as none 在我的代码中,我想用默认的姓氏升序来做gird表,用(xxx)-xxx-xxxx格式化电话号码,并将单词null替换为none,例如某些mobiel编号为null,我想显示没有

{
                    field: "LName",
                    width: 100,
                    title: "Last Name",
                    defaultSorting: true

                }, {
                    field: "DateOfBirth",
                    width: 100,
                    title: "Date of Birth",
                    type: 'date',
                    template: '#= kendo.toString(DateOfBirth,"MM/dd/yyyy") #'

                }, {
                    field: "Email",
                    width: 230,
                    title: "Email"
                }, {
                    field: "MobileNumber",
                    width: 100,
                    title: "Mobile Number"


                },

any one done this before, or have idea plz help 任何人之前都做过此事,或者有想法请帮忙

Setting a default sort is done on the data source , and can be done like this: 设置默认排序是在数据源上完成的,可以这样进行:

sort: { field: "LName", dir: "asc" }

Formatting a phone number is a bit trickier, as there is no built in support for formatting them. 格式化电话号码有点棘手,因为没有内置的格式化电话支持。 You'll have to pull the number apart, then you can use the format function to format the number (assuming your number is formatted 1234567890): 您必须将数字分开,然后可以使用格式函数来格式化数字(假设您的数字格式为1234567890):

function formatPhoneNumber(phoneNumber) {
    var piece1 = phoneNumber.substring(0, 3); //123
    var piece2 = phoneNumber.substring(3, 6); //456
    var piece3 = phoneNumber.substring(6); //7890

    //should return (123)456-7890
    return kendo.format("({0})-{1}-{2}", piece1, piece2, piece3);
}

To replace null with none use another template function. 要将null替换为none,请使用另一个模板函数。 This can also apply the phone number formatting: 这也可以应用电话号码格式:

template: '#= (MobileNumber) ? formatPhoneNumber(MobileNumber) : "none" #'

You'll need to make sure that your formatPhoneNumber function is scoped so that the kendo template can access it when binding. 您需要确保formatPhoneNumber函数的作用域是有限的,以便在绑定时kendo模板可以访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM