1

I was wondering if it would be possible to format strings (in this case the string displayed in the field OrderDate) using the "attributes:{}" thing ( I do not know how I should call that. A tag? A property?)

NOTE: This is inside a kendogrid which gets JSON data from a remote server.

NOTE 2 : The attributes:{style:text-align:center;"} works just fine.

        field : "OrderDate",
        title : "Orderdatum",
        attributes:{style:"text-align:center;"},
        width : 170,

If there is anything else that I need to provide you with, do say so.

Thanks in advance everyone! And if this looks like I haven't searched or something, then I can assure you I have.

enter image description here

I thought this might help people get an idea of how it looks. What I want to achieve in my case is that IF the data is 3-3-2009 (the selected cell/row) that it shows as 03-03-2009. Is it possible to achieve it using attributes ?

Again, thanks in advance.

Edit 2: This link tells me it is not possible to do it in CSS3. So my guess now is that I accidently have created a duplicate question. So let me rephrase my quesion: How can I format the string, not necessarily using attributes, so it looks how I explained I want it to look?

Edit 3: I was supposed to include this. As you can see what I get is a string and not a number.

schema: {
            type : "json", 
            data : "SalesOrders.SalesOrder", 
            model: {
                fields: {
                    OrderNo : {type: "string"},
                    OrderDate : {type: "string"},
                    DeliveryWeek : {type: "number"},
                    OrderTotal :  {type: "number"},
                    OBJECTID : {type: "number"},
            },

Yet again, thanks for your time to read my question.

Community
  • 1
  • 1
Turtle-kun
  • 11
  • 2
  • 7
  • Re-Formatting an HTML Element's value is not done through the HTML Element's attribute. I posted a solution as an answer. – id.ot Jul 09 '14 at 08:26

2 Answers2

0

We can combine the functionality (described in the following Kendo UI documentation) to reformat the date during the DataBound event:

http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting

http://docs.telerik.com/kendo-ui/api/web/grid#events-dataBound

[update] Here's some generic code to convey the idea:

<div id="grid"></div>
<script>
    $("#grid").kendoGrid({
  columns: [
    { field: "name" },
    { field: "age" }
  ],
  dataSource: [
    { name: "Jane Doe", age: 30 },
    { name: "John Doe", age: 33 }
  ],
  dataBound: function(e) {
    console.log("put your Date conversion logic here in the dataBound event");
  }
});

id.ot
  • 3,071
  • 1
  • 32
  • 47
0

In this scenario, you are unable to format the string using CSS3 (Like totally impossibru...)

Therefore, you need to format your JSON object once its loaded, before its passed into the grid for display.

Formatting of data (This link give you some idea on how you format the datasource)

http://www.telerik.com/forums/datasource-number-format

Formatting dates (This link give you idea on how to format dates)

http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting

If you are not comfortable with kendo formatting of dates (Yes, I hate it), you can use the sweet momentJS

http://momentjs.com/

BTW (EDITED)

Kendo grid date column not formatting

this is a quicker and cleaner way of using "template" attribute for formatting

Community
  • 1
  • 1
Shi Wei
  • 262
  • 3
  • 13
  • Thanks for trying to help but it isn't helping at all. One because I absolutely have no idea how to format JSON data (not after reading the links you included as the first one was for _numbers_ and the second one for _dates_ while I have a _string_ .) Two, I do not wish to use a template as that would require me to totally rebuild the site, which isn't really fun. But still thanks for your answer because I did learn more about formatting numbers and dates and I've already put that to use in other parts! – Turtle-kun Jul 09 '14 at 12:12