{"action":"closed","issue":{"url":"https://api.github.com/repos/ceolter/ag-grid/issues/957","repository_url":"https://api.github.com/repos/ceolter/ag-grid","labels_url":"https://api.github.com/repos/ceolter/ag-grid/issues/957/labels{/name}","comments_url":"https://api.github.com/repos/ceolter/ag-grid/issues/957/comments","events_url":"https://api.github.com/repos/ceolter/ag-grid/issues/957/events","html_url":"https://github.com/ceolter/ag-grid/issues/957","id":159768292,"number":957,"title":"[Feature] Linked Tables","user":{"login":"AmitMY","id":5757359,"avatar_url":"https://avatars.githubusercontent.com/u/5757359?v=3","gravatar_id":"","url":"https://api.github.com/users/AmitMY","html_url":"https://github.com/AmitMY","followers_url":"https://api.github.com/users/AmitMY/followers","following_url":"https://api.github.com/users/AmitMY/following{/other_user}","gists_url":"https://api.github.com/users/AmitMY/gists{/gist_id}","starred_url":"https://api.github.com/users/AmitMY/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AmitMY/subscriptions","organizations_url":"https://api.github.com/users/AmitMY/orgs","repos_url":"https://api.github.com/users/AmitMY/repos","events_url":"https://api.github.com/users/AmitMY/events{/privacy}","received_events_url":"https://api.github.com/users/AmitMY/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-06-11T11:00:22Z","updated_at":"2016-07-29T10:56:58Z","closed_at":"2016-07-29T10:56:58Z","body":"Here is a problem every front end developer encountered:\r\n\r\n> Showing a list of lets say users, and needing to show the country, but unfortunately the back end does not join the countries's table, and is busy right now, or adding that specific join makes everything slower. (Yes, they need to optimize, but sometimes they are assholes), or the back end was made a long time ago, and cannot be changed\r\n\r\nThe solution so far (with a table library, not simple code):\r\n\r\n> Send request 1 (async), get a list of users\r\n> Send request 2 (async), get a list of countries\r\n> Wait for both to finish, using a flag or something, and when both do, create a hash table of the countries, then go over the users, and do \r\n> `users[i].country_name = countries[users[i].country_code].country_name;`\r\n\r\nAnd if you have 3-4 linked tables required, it gets more complicated quickly\r\n\r\n---\r\nThere is a better solution. I tried to implement myself, but failed to understand the scope of variables, so couldn't, you'll understand in a second.\r\n\r\n- Pass to the gridOptions a parameter linkedTables, which must be an object. The key is the table's index, the value is an array or a promise.\r\nFor example:\r\n```\r\nlinkedTables: {\r\n    \"country_code\": new Promise(function (resolve, reject) {\r\n        dataFactory.getCountries().done(function (response) {\r\n            resolve(response.data);\r\n        });\r\n    }),\r\n    \"language_code\": [\r\n        {\"language_code\": \"EN\", \"language_name\": \"English\"},\r\n        {\"language_code\": \"IT\", \"language_name\": \"Italian\"},\r\n    ]\r\n}\r\n```\r\n- have a variable. lets say tableTables which is an empty object, not exposed!\r\n- have a variable, lets say agTables, which is exposed to valueGetter, and is a function.\r\n- Go over the linkedTables. If array, construct a table** from the array and the key. If promise, do a 'then' or something, and then construct the tables. After constructing a table, put it in tableTables[key]\r\n- On valueGetter, allow writing `agTables(\"country_code\", data.country_code, \"country_name\")` (valueGetter/different thing, Not cellRenderer)\r\n- If the table did not load yet, return the key.\r\n- On promise finish, reload the volatile columns (all columns using agTables are volatile)\r\n\r\nComplexity: O(1)\r\n\r\nHere is the agTables function:\r\n```\r\nfunction agTables(table, index, value) {\r\n    if(tableTables[table] === undefined)\r\n        return index;\r\n\r\n    return tableTables[table][index][value];\r\n}\r\n```\r\n\r\nHere is the hash tables building function:\r\n```\r\nfunction buildHashTable(array, key) {\r\n    var table = {};\r\n    for (var x in array) {\r\n        if (array[x][key] !== undefined)\r\n            table[array[x][key]] = array[x];\r\n    }\r\n    return table;\r\n}\r\n```\r\n\r\n---\r\nThis seems quite simple to implement.\r\nSo why am I asking you to add as a feature?\r\n\r\n- I don't think I am the only one needing something like this\r\n- It is too complex when you have a report for all of your clients for example, with 15 linked tables in O(1), or sending 15 requests and managing their flags..\r\n- Main reason? I did not understand what is the scope of valueGetter, therefor, I couldn't get to the agTables function, as much as I tried.\r\n\r\n---\r\n**Sorry for the long post, thought it would help if I lay everything down for you guys, so you will understand it is probably a work for an hour.**\r\n\r\nAlso, It looks like you aspire to be the Excel of the web. Excel has linked tables, but it is slow because it does not create indexes. Here we do create indexes, for NO PERFORMANCE IMPACT.\r\n"}}
{"actor":{"display_login":"ceolter"}}