oria / gridx

Just another powerful Dojo grid
Other
162 stars 78 forks source link

FormatSort does not work with MemoryStore #185

Open rcbell opened 10 years ago

rcbell commented 10 years ago

I'm using MemoryStore for my synchronous store, and I've discovered that it does not use the Fetch methods which FormatSort connects with to replace the comparator function, so its _createComparator method is never called. I switched to ItemFileReadStore to get my comparators to work, but this is deprecated and I'd rather use MemoryStore.

Is this working as designed, or can we anticipate a fix for this?

bridgji commented 10 years ago

I'd be interested in finding out if this is designed or not and also if a working demo with a FormatSort could be posted also.

Thanks

zhuxw commented 10 years ago

Hi, are you using the current gridx code? Both stores are supported by FormatSort since gridx 1.0. Only in gridx1.0alpha the new store was not supported. You can check the test page for gridx sort. As I remembered it is gridx/tests/test_grid_singleSort.html, or gridx/tests/test_grid_sort.html. The FormatSort is demoed there, and the Memory store is used.

On Thu, Mar 13, 2014 at 8:53 PM, bridgji notifications@github.com wrote:

I'd be interested in finding out if this is designed or not and also if a working demo with a FormatSort could be posted also.

Thanks

Reply to this email directly or view it on GitHubhttps://github.com/oria/gridx/issues/185#issuecomment-37528984 .

Best Regards.

Oliver (Zhu Xiao Wen)

bridgji commented 10 years ago

Thanks for the quick response. I am using the current version. Thanks for pointing me at the test page. It is setup going against the ItemFileReadStore but was able to just change it to use the memory store and the custom sort worked fine. Now that I have a working copy I should be able to debug my page and see why its failing.

rcbell commented 10 years ago

Sorry that I haven't had a chance to respond. I also noticed that the test code is using ItemFileReadStore, and that's when I decided to stop trying to get Memory Store to work. How did you get it to? I found that the FormatSort uses aspect to hook into the onBeforeFetch and onAfterFetch of the cache, but the Memory store does not have these methods. What did you have to do to get this working?

I am using Gridx 1.1

bridgji commented 10 years ago

I was able to get the demo working with memory by changing the required support file from the 'gridx/tests/support/stores/ItemFileReadStore; to the 'gridx/tests/support/stores/Memory' This made it so the storeFactory call created a memory store and everything worked. Now I'm still having trouble getting this to work in my application.

I'm using the newest version of gridx 1.3

zhuxw commented 10 years ago

hi, onBeforeFetch and onAfterFetch are internal events of gridx cache, not store. If you check FormatSort code you can find that gridx changes dojo/data/util/sorter for old stores (like ItemFileWriteStore), and directly passes sort function in request for new stores (like dojo/store/Memory).

On Fri, Mar 14, 2014 at 11:34 PM, rcbell notifications@github.com wrote:

Sorry that I haven't had a chance to respond. I also noticed that the test code is using ItemFileReadStore, and that's when I decided to stop trying to get Memory Store to work. How did you get it to? I found that the FormatSort uses aspect to hook into the onBeforeFetch and onAfterFetch of the cache, but the Memory store does not have these methods. What did you have to do to get this working?

I am using Gridx 1.1

Reply to this email directly or view it on GitHubhttps://github.com/oria/gridx/issues/185#issuecomment-37660256 .

Best Regards.

Oliver (Zhu Xiao Wen)

zhuxw commented 10 years ago

Hi, gridx/tests/support/store/* are just a bunch of utility functions to easily create stores in gridx test pages, so that I don't need to write the same code over and over. Nothing magic here. :-)

On Sat, Mar 15, 2014 at 12:35 AM, bridgji notifications@github.com wrote:

I was able to get the demo working with memory by changing the required support file from the 'gridx/tests/support/stores/ItemFileReadStore; to the 'gridx/tests/support/stores/Memory' This made it so the storeFactory call created a memory store and everything worked. Now I'm still having trouble getting this to work in my application.

Reply to this email directly or view it on GitHubhttps://github.com/oria/gridx/issues/185#issuecomment-37668090 .

Best Regards.

Oliver (Zhu Xiao Wen)

bridgji commented 10 years ago

I'm still having trouble in my code. Its not hitting the comparator. I assume I'm making some rookie mistake as I'm relatively new to JavaScript and gridx. The grid does sort and run .

I'm creating my grid
require([ "gridx/Grid", "gridx/core/model/cache/Sync", "gridx/modules/ColumnWidth", "gridx/modules/ColumnResizer", "gridx/modules/Sort", "gridx/modules/extendedSelect/Row", "gridx/core/model/extensions/FormatSort",

 inspectionsGrid =new Gridx({
                            id: "inspectionsGrid",
                            cacheClass: "gridx/core/model/cache/Sync",
                            store: indexStore,
                            structure: layoutInspection,
                            modelExtentions: ['gridx/core/model/extensions/FormatSort'],
                            baseSort :[{attribute: "required", descending: true}],
                            modules: ["gridx/modules/Sort",
                                        "gridx/modules/ColumnResizer",
                                        "gridx/modules/extendedSelect/Row",
                                        "gridx/modules/IndirectSelectColumn",
                                        "gridx/modules/TouchVScroller",
                                        "gridx/modules/RowHeader",
                                        "gridx/modules/VirtualVScroller"] 
                        });
                        inspectionsGrid.placeAt("inspectionsGridContainer");

                        inspectionsGrid.startup();

From my function to get data and return a memory store

Inspections.forEach(function (inspection) { var cv = { "id": parseInt(inspection.key) , "hypID": "<a id=\"" + inspection.key.toString() + "\" href=\"" + inspection.Hyperlink.toString() + "\" target=\"_blank\" >" + inspection.key.toString() + "", "type": (inspection.insp_type ? null : " ", inspection.insp_type), "description": (inspection.insp_type_short ? null : " ", inspection.insp_type_short), "requested": (inspection.req_date ? null : " ", inspection.req_date), "scheduled": (inspection.sched_date ? null : " ", inspection.sched_date), "preformed": (inspection.perf_date ? null : " ", inspection.perf_date), "trade": (inspection.trade_type_short ? null : " ", inspection.trade_type_short) }

            retval[count] = cv;
            ++count;

    });

layoutInspection = [

        {
        id: "hypID",
        field: "hypID",
        name: "Inspection Number",
        sortable: true,
        width: "100px" 

    }, {
        id: "type",
        field: "type",
        name: "Inspection Type",
        sortable: true,
        width: "100px" 
    }, {
        id: "description",
        field: "description",
        name: "Description",
        sortable: true,
        width: "100px" 
    }, {
        id: "requested",
        field: "requested",
        name: "Requested",
        width: "100px",
        sortable:true,
        comparator: function (v1, v2) {
            // let's assume data in this column are date strings. We need to transform them to Date object for comparison.
            v1 = new Date(v1);
            v2 = new Date(v2);
            return v1 - v2;

        }

    }, {
        id: "scheduled",
        field: "scheduled",
        name: "Scheduled",
        width: "100px"

    }, {
        id: "preformed",
        field: "preformed",
        name: "Preformed",
        width: "100px"

    }, {
        id: "trade",
        field: "trade",
        name: "Trade",
        width: "100px"

    }];

      //var m = new dojo.data.ItemFileReadStore({
      //    data: {
      //        "identifier": "id",
      //        items: retval
      //    }
      //});
    var m = new Memory({ data: retval , size : 100});

    return m;
bridgji commented 10 years ago

I end up in the sort.js instead of the FormatSort when I run my code but when it runs the test its ending up in the formatsort.js. I have the same modules ,extensions defined in the grid and the same store type. In looking at the code I'm not sure what triggers it to choose sort with FormatSort or how to debug why i'm not hitting that code. It seems like its not seeing the modelextentions somehow.