     console.log "Loaddata"
     transaction = @db.transaction ["catalog"], "readonly"
     filesStore = transaction.objectStore "catalog"
-    cursor = filesStore.openCursor()
+    cursor = filesStore.index("catalogByGrid").openCursor()
     @loadFromCursor cursor, (rec)->true
 
   loadDataFor: (gridN, gridM, funcId) ->
+    transaction = @db.transaction ["catalog"], "readonly"
+    catalog = transaction.objectStore "catalog"
+    catalogIndex = catalog.index "catalogByGrid"
+    cursor = catalogIndex.openCursor()
+    @loadFromCursor cursor, (rec)->
+      (rec.gridN is gridN) and (rec.gridM is gridM) and ((funcId is null) or (rec.funcId is funcId))    
+    
+  loadDataFor1: (gridN, gridM, funcId) ->
     transaction = @db.transaction ["catalog"], "readonly"
     filesStore = transaction.objectStore "catalog"
     #create range

      rqStoreData.onerror = (e)=>
        console.log "Error storing data #{e.target.error}"
      rqStoreData.onsuccess = (e)=>
        console.log "Stored data OK, key is #{e.target.result}"
        #console.dir e.target
        key = e.target.result
        #console.log "Store catalog record"
        catalogRecord =
          gridN: (Math.random()*4)|0+4
          gridM: (Math.random()*4)|0+4
          name: "File #{i+1}"
          funcId: "B 3 S 2 3"
          funcType: "binary"
          base: 'e'
          offset: M.eye()
          field: key


    console.log "Create files and database store"
    @fileStore = db.createObjectStore "files", {autoIncrement: true}
    @catalogStore = db.createObjectStore "catalog", {autoIncrement: true}

    @catalogIndex = @catalogStore.createIndex "catalogByGrid", ['gridN', 'gridM', 'funcId', 'name', 'time'], {unique: false}
    
    @populated = false

