0

YUI DataTable doesn't display values for 'dot.notation' keys (though there seems to be a weird trick that works). What's the best way to remedy this? I want a 'correct' answer, not the current one I have where I flatten nested objects AND retain the nested objects (both must be present for this to currently work).

example data (3rd datum works because of weird duplication trick)

var table = new Y.DataTable({
    columns: ['key', 'dot.notation'],
    data: [{
        // broken
        key: 'value',
        'dot.notation': 5
    }, {
        // broken
        key: 'value',
        dot: {
            notation: 5
        }
    }, {
        // displays
        key: 'value',
        'dot.notation': 5,
        dot: {
            notation: 5
        }
    }]
});

http://jsfiddle.net/dirkraft/ERk2d/

Jason Dunkelberger
  • 1,207
  • 14
  • 18

1 Answers1

1

Using DataSchema is the correct way to handle this. I believe that the dotted key version used to work but then changes in version 3.5 stopped this working

YUI().use('datatable', 'datasource','datasource-jsonschema', function (Y) {

    var ds = new Y.DataSource.Local({
        source: [{
            // broken
            key: 'value',
            'dot.notation': 5
        }, {
            // broken
            key: 'value',
            dot: {
                notation: 5
            }
        }, {
            // displays
            key: 'value',
            'dot.notation': 5,
            dot: {
                notation: 5
            }
        }]
    });

    ds.plug({fn: Y.Plugin.DataSourceJSONSchema, cfg: {
    schema: {
        resultFields: [
            "key",
            {
                key:'foo',
                locator:'dot.notation'
            }
        ]
    }
}});

    var table = new Y.DataTable({
        columns: ['key', 'foo'],
        caption: 'Better Now'
    });
    table.plug(Y.Plugin.DataTableDataSource, {
        datasource: ds
    });
    table.render('#lolol');
    table.datasource.load();

});

http://jsfiddle.net/ERk2d/3/

barnyr
  • 5,678
  • 21
  • 28
  • I've just noticed that the code above works for all three objects in the data, including the first, which uses the 'dot.notation' form, which I wouldn't have expected. It seems that DataSchema prefers the subkey values though, which is how I'd hope it'd work – barnyr Jan 27 '14 at 06:09
  • I'm actually using what YUI calls a "custom sync layer", which I think may circumvent usage of certain kinds of plugins like the DataSourceJSONSchema. But at least with that I can set a breakpoint and figure out what it's doing. Thanks – Jason Dunkelberger Jan 27 '14 at 16:33
  • no problems. Do post what your solution is. Are you using your own sync layer or one of the ones provided by YUI? – barnyr Jan 27 '14 at 16:47
  • My own is akin to http://yuilibrary.com/yui/docs/model-list/#the-sync-method. What's more complicated is that I have columns added and removed on the fly based on the response. I haven't yet bothered to go down that rabbit hole, first converting my custom sync to a YUI DataSource, and then also seeing if it's even possible to dynamically update the DataSourceJSONSchema plugged into it. – Jason Dunkelberger Jan 28 '14 at 18:09