bind data client side before render (using data passed from server)
bind data client side before render (using data passed from server)
Hi,
i've lots of records returned from server, and some data is replicate for each row.
So, I'd like to create a dictionary server side, pass with the table "data" JSON, and bind each ID (for some field) with this dictionary.
What's the best way to do it? createdRow?
Not sure which is the value to pass to it:
dtGrid = $("#grid").DataTable({
ajax: {
url: "@(Url.Action("GetWorktypes", "Worktypes"))"
},
columns: [
{ data: "ID", title: "", visible: false, searchable: false },
{ data: "ClinicID", title: "", visible: false, searchable: false },
{ data: "MedicalID", title: "", visible: false, searchable: false },
{ data: "PatientID", title: "", visible: false, searchable: false }
],
createdRow: function (row, data, dataIndex) {
// here?
}
});
data
contains the row, and I'll return a proper patientsDictionary
dictionary so I can bind PatientID with Name/Surname with dictionary...
This way doesn't works:
createdRow: function (row, data, dataIndex, patientsDictionary) {
// dunno is correct
}
Any clues? Thanks
Replies
Hi,
Thanks for your question, but I'm not entirely sure I understand. If you want to create a server-side dictionary to do row replication, I'm not clear on why you would use anything on the client-side for it?
Allan
Because I want to build the value of Dictionary on Client side.
Example:
1 = Bill Gates
2 = Steve Jobs
...
I will pass for each row just the ID of the person, plus a single dictionary.
Than, client side, I want to associate the id to the dictionary.
In this way, for each person (let say 17k records) I just use an integer, saving data from the json returned from server.
Is it more clear?
It's best to use
colums.render
for that - you can change what goes into the cell. It might be worth looking atserverSide
- see examples here - as only a single page of data is sent to the client.Cheers,
Colin
@colin: but how can I access custom data (from json) from that function?
Any example?
Thanks
One option is to use
ajax.dataSrc
as a function. In the function place the custom data into a global variable. Incolumns.render
use that varaible how you like.Kevin
Another option is to call
ajax.json()
- this is the last data returned.Colin
ajax.dataSrc seems to works perfect! thanks dudes