Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime from json result #58

Open
wickstargazer opened this issue Apr 25, 2014 · 2 comments
Open

Datetime from json result #58

wickstargazer opened this issue Apr 25, 2014 · 2 comments
Labels

Comments

@wickstargazer
Copy link

Hi, i am using bbgrid in c# MVC development.
The problem i get is, the Date(xxxx) the json data gets back from the server is not rendered as date in the grid.

I am trying to find a way to solve it.

By the way, i have added a couple of events in the bbgrid code, like such

       ContentListGrid.bind('sort', function (event) {
            //console.log(event);
            $('.confirm-delete').on('click', enableDeleteButton);
        });
        ContentListGrid.bind('aftersort', function () {
            $('.star').on('click', onHighlight);
            $('.confirm-delete').on('click', enableDeleteButton);
        });
        ContentListGrid.bind('afterfilter', function () {
            $('.star').on('click', onHighlight);
            $('.confirm-delete').on('click', enableDeleteButton);
        });
        ContentListGrid.bind('afterpageChanged', function () {
            $('.star').on('click', onHighlight);
            $('.confirm-delete').on('click', enableDeleteButton);
        });

to help sustain some events after the page changes or sorting is commenced.
If you would like me to submit up to branch, will do so :)

@wickstargazer
Copy link
Author

This is how i solved it in the render function

switch (col.type) {
case 'date':
var value = self.getPropByStr(self.model.attributes, col.name);
if (value) {
var regex = /-?\d+/;
var m = regex.exec(value);
var datetimeValue = new Date(parseInt(m[0]));
if (col.dateformat) {
//datetimeValue.format(col.dateformat);
}
col.value = datetimeValue;
}
break;
default:
col.value = self.getPropByStr(self.model.attributes, col.name);
break;
}

putting this into the config for column

{ title: 'Published Date', name: 'PublishedOn', index: true, sorttype: 'date', type: 'date', dateformat: 'dd/m/yy' }

@wickstargazer
Copy link
Author

Lastly for the formatting

if (col.dateformat) {
if (!$.datepicker)
throw new Error("Cannot format date, please include jquery datepicker, column name : " + col.name );
datetimeValue = $.datepicker.formatDate(col.dateformat, datetimeValue);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants