admin管理员组

文章数量:1328589

I am using DGRID to display data. I am aware i can query records in the store using store.query and insert records into the store using store.put and so on however i would like to do an update of the store. How can i update a record in the store?

I would prefer updating the memory store and then push that back into the database instead of updating the database first and then refreshing the memory store.

Data

 var data = [
            { id:"1", idType: "Passport", idNumber: "12121545WWW" },
            { id:"2",idType: "Drivers Permit", idNumber: "11212154515 FF"},
            { id:"3",idType: "Electoral Identification", idNumber: "425123123121"}
        ];

Functions

Add data

Store.put({id: enteredId, idNumber:enteredIdNumber,idType:enteredIdType})

Query data

Store.query({idType: enteredIdType})

Update data - i am confused how this is done

Store.update({idNumber:enteredIdNumber,idType:enteredIdType})

I am using DGRID to display data. I am aware i can query records in the store using store.query and insert records into the store using store.put and so on however i would like to do an update of the store. How can i update a record in the store?

I would prefer updating the memory store and then push that back into the database instead of updating the database first and then refreshing the memory store.

Data

 var data = [
            { id:"1", idType: "Passport", idNumber: "12121545WWW" },
            { id:"2",idType: "Drivers Permit", idNumber: "11212154515 FF"},
            { id:"3",idType: "Electoral Identification", idNumber: "425123123121"}
        ];

Functions

Add data

Store.put({id: enteredId, idNumber:enteredIdNumber,idType:enteredIdType})

Query data

Store.query({idType: enteredIdType})

Update data - i am confused how this is done

Store.update({idNumber:enteredIdNumber,idType:enteredIdType})
Share Improve this question asked Mar 26, 2014 at 20:22 devdardevdar 5,65428 gold badges103 silver badges156 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You seem to be a bit confused about the dojo/store API.

  • store.add(item) is used to add new items
  • store.put(item) is used to update items, but can often also be used to add new ones with a specific ID
  • store.remove(id) is used to delete items

If you wrap your store with dojo/store/Observable, e.g. new Observable(new Memory({ data: ... })), then the grid will update automatically when add / put / remove are called.

See the dojo/store documentation for more information.

If you are wondering how to update records via the grid itself, have a look at the editor column plugin.

Do you have an example of what your store structure is like? Normally if your store identifier is your "id", putting it again will just update the row. After putting new data, you can just call on grid.refresh() and it should update your table.

本文标签: javascriptDgrid update data storeStack Overflow