<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ondrej Hlouzek on Medium]]></title>
        <description><![CDATA[Stories by Ondrej Hlouzek on Medium]]></description>
        <link>https://medium.com/@ondrej.hlouzek?source=rss-37b6fb9ad0ff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*URP6oa8ulQff4RSeEqG7cg.jpeg</url>
            <title>Stories by Ondrej Hlouzek on Medium</title>
            <link>https://medium.com/@ondrej.hlouzek?source=rss-37b6fb9ad0ff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:26:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ondrej.hlouzek/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Telegram did not send a verification SMS code. SOLVED]]></title>
            <link>https://medium.com/swlh/telegram-did-not-send-a-verification-sms-code-solved-c8994193713e?source=rss-37b6fb9ad0ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8994193713e</guid>
            <category><![CDATA[verification]]></category>
            <category><![CDATA[login]]></category>
            <category><![CDATA[messenger]]></category>
            <category><![CDATA[telegram]]></category>
            <dc:creator><![CDATA[Ondrej Hlouzek]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 19:19:52 GMT</pubDate>
            <atom:updated>2021-12-09T19:19:52.502Z</atom:updated>
            <content:encoded><![CDATA[<p>I was unable to log in to the telegram application. I didn’t receive a verification SMS code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XXYbO3M6uX8bVCb8" /><figcaption>Photo by <a href="https://unsplash.com/@solomin_d?utm_source=medium&amp;utm_medium=referral">Dima Solomin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>What happened?</h4><p>In a nutshell. I was unable to log in to the telegram application. I didn’t receive a verification SMS code. Telegram support is not responding and I am frustrated.</p><p>As every day, I log on to telegram and communicate with my users. But one day everything changed. For some reason, I unsubscribe from the telegram. The surprise was that I had to enter a verification code to log in, but I didn’t get it.</p><h4>Small code, big problem</h4><p>I waited 5 minutes, 10 minutes, but the code still didn’t come. So I tried to log in again. When I read the notice carefully, I found that the code was sent to me, but to another device where I was logged on. <strong>But I was not logged on to another device!!</strong></p><p>I got into a situation where I was not able to log on to any device that I had a telegram installed on. After several attempts, the telegram even blocked my account for 20 hours !!!! Incredibly. There was nothing left but to wait and try again after 20 hours. Unsuccessfully again and blocked again.</p><p>An even bigger problem arose when I tried to solve everything with the help of Telegram. They have written in the help that they deal with tens of thousands of messages from users every day and that they do not have time to solve all queries. And so it really happened. I waited a week for an answer, and still no one answered. I really tried everything. I wanted to scream.</p><h4>I found a solution</h4><p>After three sleepless days, I finally found a solution. And I believe that it will work for you as well. 😎😎😎</p><h4>Observations</h4><p>I have found that the device is the only one that is installed on. That is, a telegram on a mobile phone or computer installed using a windows store or using a classic installer.</p><p>If you use the telegram website, you will never receive the SMS code. So, do not perform the procedure on the website. Otherwise you will not be able to log in.</p><h4>Solution</h4><p>To be able to log in to our account (in order to receive a verification SMS), we need a<strong> new phone number</strong>.</p><ol><li>If you do not have a<strong> new telephone number</strong> registered in the telegram, register it. If you are already registered, go to point 2.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*FHku1mZETqBv5O5J-PMRqQ.png" /></figure><p>Enter your <strong>new phone number</strong> and click NEXT. You will receive an SMS with a verification code.</p><p>2. Log in to your new account.</p><p>3. Now comes the magic. In the new account, click the arrow next to Username. The menu will open, where you can click on Add account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*fQBDXs0pnZ36a53G0dBb_g.png" /></figure><p>4. This time, enter the <strong>original phone number </strong>of the accounts you are trying to sign in to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*mci71YFGLRN7Q5op9DIr_g.png" /></figure><p>5. And what happened? This time you will receive a verification SMS to the original telephone number. However, this is a number that is used to merge accounts. Enter this number. Complete the migration</p><p>6.👍👍👍 Great!!! We already have data from the original account in the new account. For many of you, it is already enough. But we’ll make it better.</p><p>7. Now try (via the mobile or app app, not the website) signing in to your original account again. Voala. Verification SMS has arrived! And you can log in to your account.</p><p>8. I hope I helped you and you were able to log in to your account.</p><p>If you like this article and it helps you, you can buy me coffee. I love coffee👍</p><figure><a href="https://www.buymeacoffee.com/hlouzek"><img alt="" src="https://cdn-images-1.medium.com/max/289/1*Tvx8QQ255eAQG9cNlfJr_w.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8994193713e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/telegram-did-not-send-a-verification-sms-code-solved-c8994193713e">Telegram did not send a verification SMS code. SOLVED</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How $$$ I Earned in July]]></title>
            <link>https://medium.com/@ondrej.hlouzek/how-i-earned-in-july-dc49d6f61ea6?source=rss-37b6fb9ad0ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc49d6f61ea6</guid>
            <category><![CDATA[money]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[partner-program]]></category>
            <category><![CDATA[freelancing]]></category>
            <category><![CDATA[work]]></category>
            <dc:creator><![CDATA[Ondrej Hlouzek]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 18:52:46 GMT</pubDate>
            <atom:updated>2020-07-31T18:46:11.419Z</atom:updated>
            <content:encoded><![CDATA[<p>A transparent look at my July partner program Earnings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gq_q7VHPyxKaTECW" /><figcaption>Photo by <a href="https://unsplash.com/@alexandermils?utm_source=medium&amp;utm_medium=referral">Alexander Mils</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I read more and more in new articles about how you make a lot of money on the <strong>medium </strong>and how you want to share with others how much you have earned.</p><p>I wasn’t the only one who started to deal with it. I started browsing the internet and watching the stories of individual people about how to make money writing about what you enjoy. You will be happy to share your experience with others. It sounds wonderful and you can make money.</p><p>So I decided to go into it and try to write something like that. I have 20 years of experience in the IT field and programming. So I started writing.</p><p>I thought that I would write something that I would not be ashamed of and that I would describe a specific topic of LINQ in javascript, which is almost non-existent on the Internet.</p><p><a href="https://medium.com/@ondrej.hlouzek/data-manipulation-in-javascript-using-linq-f3759e00aceb">Data Manipulation in JavaScript Using LINQ</a></p><p>I spend a long 30 hours writing this article. I wanted it to contain not only a description of the functions of the technology, but also a lot of examples and practical experience and a complete list of auxiliary custom components that further expand the functionality.</p><p>So I dedicate 30 hours of my life and free time to the whole article. I thought the reward for that could be less compensation.</p><p>It is written everywhere how many millions of people follow such articles, and that if you write an interesting article, you will be interested in it.</p><p>The reality was harsher than I expected. this will be described in the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJ19xppMBZkQ8kRRZhJO7g.png" /></figure><p>After 7 days of publishing the article, which was also confirmed by the curator and published, I got the number 177 views. On sites that are watched by millions of people? !!! I probably had to write a very bad article … or rather a headline, because only 177 readers opened it. After the publication, the article was opened by about 120 readers the next day, the following days, but this one lost all interest.</p><p>I also contacted other publications to publish my article. Unfortunately, I came across a lack of interest from the other side. In fact, they didn’t even need to read my article.</p><h3>Conclusion</h3><p>From the 30 hours of work he came out of, I’m not afraid to say a professional article I earned an amazing $ 0.69. In terms of $ 0.023 per hour. In fact, I’ve earned more as a programmer.</p><p>From the initial enthusiasm, it soon became a great disappointment. I wanted to write a lot of interesting articles from my many years of experience and publish them to the general public through <strong>Medium</strong>. My conclusion is that I prefer to keep my experience to myself.</p><p>Unfortunately, I’m probably at a time when everyone is only interested in bullshit. Articles in the style, “<strong>Learn to program like a pro for 10 minutes</strong>” or “<strong>5 tricks on how to be a better programmer</strong>”. Nobody is interested in professional and detailed publications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc49d6f61ea6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Manipulation in JavaScript Using LINQ]]></title>
            <link>https://medium.com/swlh/data-manipulation-in-javascript-using-linq-f3759e00aceb?source=rss-37b6fb9ad0ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3759e00aceb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[linq]]></category>
            <dc:creator><![CDATA[Ondrej Hlouzek]]></dc:creator>
            <pubDate>Thu, 23 Jul 2020 12:26:03 GMT</pubDate>
            <atom:updated>2022-03-28T06:48:12.604Z</atom:updated>
            <content:encoded><![CDATA[<h3>LINQ in Javascript</h3><p>LINQ in Javascript is a great simple tool for manipulating data collections in javascript. You can easily transform, sort, select and combine data collections using javascript commands in react, angular, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*heeeoLfKw98hrYXO" /><figcaption>Photo by <a href="https://unsplash.com/@claudiolcastro?utm_source=medium&amp;utm_medium=referral">Cláudio Luiz Castro</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>LINQ (Language Integrated Query)</h3><p>LINQ is the name for a set of technologies that can be used to make adjustments to data sources in simple and easy-to-read operations. In our case, we will be based on an array of objects, which is widely used, especially in javascript.</p><p>Who program in C# certainly know advantage of this technology, which has existed since 3.0 version under the .NET Framework 3.5.</p><h3>Why LINQ in javascript?</h3><p>The benefit of LINQ is a simple and readable syntax for accessing and manipulating data. It makes easier transformation of data structures into others, sorting and merging data between multiple sources.</p><h3>Data sources</h3><p>A huge advantage is that the source does not have to be just a simple an array (table) but it can be a complex structured array of data. Nesting objects and collections in other objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*Nlm-VY6qJ8WorMgwYRHuIA.png" /></figure><h3>Project goal</h3><p>In this article, we will be based exclusively on practice and the most commonly used forms, which often occur in real projects. We will not show only simple examples. In most cases, more complex adjustments are needed, both at the request of superiors and to optimize and speed up queries. Next, I will deal with cases that the developer often solves when manipulating data, but on the internet, the process is often confusing or unnecessarily complicated.</p><p>The aim of this project is to demonstrate technology that will simplify your work and solve situations that often occur in real projects and using javascript is much more complicated, almost “impossible”. I believe that you will find the benefits of this technology and will be a good helper in future. From my many years of experience, I can assure you that this technology will save you a lot of time and nights, and at the same time this code will be much more readable for developers who will read back your code.</p><p>It’s interesting? so let’s do it!</p><h3>Npm LINQ</h3><p>Thanks to the efforts of the developers who created the <a href="https://www.npmjs.com/package/linq"><strong>npm linq</strong></a> package, this technology can be used in javascript projects or, as in my case, in the react web framework.</p><p>Install the npm package</p><pre>npm install linq</pre><p>Import LINQ into the project</p><pre>Import Enumerable from &#39;linq&#39;;</pre><pre>or</pre><pre>const Enumerable = require(‘linq’);</pre><h3>Method of writing</h3><p>The method of writing can be divided into three parts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*SuB7BDSrdSGHJkxNMsfVKw.png" /></figure><ul><li><strong>Input </strong>— Wrap array and gain access to Enumerable.from() transformation methods</li><li><strong>Transformations </strong>— Transformation, sorting and merging of data. Using transformation commands, you can transform data into new structures, create new objects and connect multiple data sources into one .select(), .groupBy(), .join() ...</li><li><strong>Output </strong>— return the result to the array using the .toArray()method. Calling the .toArray() command calls the operation itself and returns the result in the collection of the Enumerable&lt;T&gt; element.</li></ul><h3>Enumerable.from()</h3><pre><strong>Enumerable.from&lt;T&gt;(obj: T[]): IEnumerable&lt;T&gt;;</strong></pre><p>To access the advantages of LINQ technology, we use the static method Enumerable.from(obj: T[]) which returns an object of type IEnumerable&lt;T&gt;. IEnumerableis an interface of collection and T is an object of generic type (collection item).</p><pre>var _arr = [1, 2, 3, 4];<br>var _linq = Enumerable.from(_arr);</pre><p>Wrapping the array with this static command gives us access to a large number of commands that can be used to manipulate data. A list of all functions can be found in the <a href="https://github.com/mihaifm/linq"><strong>github repository </strong></a>in the <a href="https://github.com/mihaifm/linq/blob/master/linq.d.ts"><strong>linq.d.ts</strong></a> file.</p><p>In practice, you will certainly encounter a situation where you want to generate a numerical series instead of data. For example, you may want to display data in a row over days. There are a number of methods available to help you with this. For example:</p><pre>make&lt;T&gt;(element: T): IEnumerable&lt;T&gt;;</pre><pre>range(start: number, count: number, step?: number): IEnumerable&lt;number&gt;;</pre><pre>repeat&lt;T&gt;(element: T, count?: number): IEnumerable&lt;T&gt;;</pre><pre>toInfinity(start?: number, step?: number): IEnumerable&lt;number&gt;;</pre><p>Probably the most interesting for us will be the range method.</p><h3>Enumerable.range()</h3><pre><strong>range(start: number, count: number, step?: number): IEnumerable&lt;number&gt;;</strong></pre><p>This method returns a collection of consecutive numbers. start says the starting number. count the number of iterations and a step with a default value of 1 by how much the iterator moves on the next cycle. E.g. for range (10, 5, 2) the result will be 10, 12, 14, 16, 18, 20.</p><h3>Enumerable.make()</h3><pre><strong>export function make&lt;T&gt;(element: T): IEnumerable&lt;T&gt;;</strong></pre><p>If you have an object and want to convert it to a collection of objects with one element, use the make method. Why would you do something like that? For example, if you use a grid to display it, it probably expects an IEnumerable &lt;T&gt; data collection on the input.</p><h3>Enumerable.repeat()</h3><pre><strong>export function repeat&lt;T&gt;(element: T, count?: number): IEnumerable&lt;T&gt;;</strong></pre><p>The repeat function generates a collection of a specified amount of a particular T element.</p><h3>Arrow function</h3><p>Using the arrow functions, we get an even more readable code. This notation clearly indicates that we want to sort in descending order by the name field. Therefore, we will prefer this type of notation in the rest of the article.</p><pre>orderByDescending(item =&gt; item.name);</pre><p>While the following notation is much less readable</p><pre>orderBy((item) { return { item.name }});</pre><h3>Select</h3><blockquote>Projects each element of a sequence into a new form.</blockquote><pre><strong>select&lt;TResult&gt;(selector: (element: TSource, index: number) =&gt; TResult): IEnumerable&lt;TResult&gt;;</strong></pre><p>The select method is used to transform the source data into a new structure. The method is called for each TSource element and returns a new element of type TResult. It helps us to simply transform an object into a new object array structure, extend an existing object with new properties, or modify existing properties.</p><pre>var array = [<br>    {name: &#39;ondrej&#39;, lastname: &#39;hlouzek&#39;, age: 38},<br>    {name: &#39;jakub&#39;, lastname: &#39;hlouzek&#39;, age: 39}<br>];</pre><pre>var result = Enumerable.from(array)<br>     .<strong>select</strong>(user =&gt; ({<br>         first_name: user.name,<br>         last_name: user.lastname,<br>         year_of_birth: 2020 - user.age, <br>         adult: ((user.age) &gt;= 18)<br>     })).toArray();</pre><p><a href="https://stackblitz.com/edit/linq-select">https://stackblitz.com/edit/linq-select</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*7V4mfbX1LP5nyLx4P36_9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*jLafB6r8ywSOXuw5b9QRuQ.png" /></figure><h4>Spread operator in select</h4><p>Using the spread operator, you can easily extend and modify an existing object. For example, if you want to extend an existing object structure with two new properties. See the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax"><strong>MDN documentation</strong></a> for more information on spread syntax.</p><pre><strong>var result = Enumerable.</strong>from(array)<br>     .<strong>select</strong>(user =&gt; ({<br>          <strong>...user</strong>,<br>          full_name:`${user.name} ${user.lastname}`,<br>          year_of_birth: 2020 - user.age<br>     }))<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-spread">https://stackblitz.com/edit/linq-spread</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*s9e_yk-F4mYLzsGwNHaAnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*oqiDuDVLwUmLZECNrtfR7g.png" /></figure><h4>Indexing records</h4><p>The Select method provides another parameter, the select (T, number) iterator. It tells the number of the currently executed line. In practice, it is often required to have a serial number for each record. In our example, the serial number of the user. Let’s take an example.</p><pre>var result = Enumerable.from(array)<br>     .<strong>select</strong>((user, <strong>index</strong>) =&gt; ({<br>          ...user,<br>          <strong>id: index + 1</strong><br>     }))<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-select-index">https://stackblitz.com/edit/linq-select-index</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*oFYjRzPlZa2aAKyqALGhKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*E5KC4uHRTfBGqTCMRPlRFw.png" /></figure><h4>Example from practice</h4><p>We want to display a list of users and their current age calculated using their date of birth. For this case I will use the package “moment”. Install this package npm install moment.</p><pre>var result = Enumerable.from(array)<br>.select(user =&gt; ({<br>     first_name: user.name,<br>     last_name: user.lastname,<br>     year_of_birth: moment().diff(user.day_of_birth, &#39;year&#39;)<br>})).toArray();</pre><p><a href="https://stackblitz.com/edit/linq-select-moment">https://stackblitz.com/edit/linq-select-moment</a></p><p>moment() returns the current date, and the diff example calculates the difference from today and day in the user.day_of_birth variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*D-kq9SeXPw1BB2_TT5iukA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*PqHuLq2i4kutQ5L4RNFBqw.png" /></figure><h3>First, FirstOrDefault</h3><blockquote>Returns the first element of a sequence.</blockquote><pre><strong>first(predicate?: (element: T, index: number) =&gt; boolean): T;<br>firstOrDefault(predicate?: (element: T, index: number) =&gt; boolean, defaultValue?: T): T | undefined;</strong></pre><p>first returns the first element of the collection. If no element exists in the collection, the application throws an exception. FirstOrDefault returns the default value if the collection is empty.</p><pre>var array = [<br>{name: &#39;ondrej&#39;, lastname: &#39;hlouzek&#39;, age: 38},<br>{name: &#39;jakub&#39;, lastname: &#39;hlouzek&#39;, age: 39}<br>];</pre><pre>var result = Enumerable.from(array)<br>     .orderBy(o =&gt; o.name)<br>     .<strong>first</strong>();</pre><p><a href="https://stackblitz.com/edit/linq-first">https://stackblitz.com/edit/linq-first</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*WCnIzrTFKnOyPpceLVKXaw.png" /></figure><h3>Last, LastOrDefault</h3><blockquote>Returns the last element of a sequence.</blockquote><pre><strong>last(predicate?: (element: T, index: number) =&gt; boolean): T; lastOrDefault(predicate?: (element: T, index: number) =&gt; boolean, defaultValue?: T): T | undefined;</strong></pre><p>last returns the last element of the collection. If no element exists in the collection, the application throws an exception. LastOrDefault returns the default value if the collection is empty.</p><pre>var array = [<br>{name: &#39;ondrej&#39;, lastname: &#39;hlouzek&#39;, age: 38},<br>{name: &#39;jakub&#39;, lastname: &#39;hlouzek&#39;, age: 39}<br>];</pre><pre>var result = Enumerable.from(array)<br>     .orderBy(o =&gt; o.name)<br>     .last();</pre><p><a href="https://stackblitz.com/edit/linq-last">https://stackblitz.com/edit/linq-last</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*DPfnit4XZunH8lsgbGuzSA.png" /></figure><h3>Single, SingleOrDefault</h3><blockquote>Returns a single, specific element of a sequence.</blockquote><pre><strong>single(predicate?: (element: T, index: number) =&gt; boolean): T; singleOrDefault(predicate?: (element: T, index: number) =&gt; boolean, defaultValue?: T): T | undefined;</strong></pre><p>The single method returns an object only if the collection to which it is applied has only one element. In the case of singleOrDefault, it returns an object only if the collection to which it is applied returns a single element or an empty collection. If the collection contains 2 or more elements, an exception is thrown.</p><pre>var array = [<br>{name: &#39;ondrej&#39;, lastname: &#39;hlouzek&#39;, age: 38}<br>];</pre><pre>var result = Enumerable.from(array)<br>     .<strong>single</strong>();</pre><p><a href="https://stackblitz.com/edit/linq-single">https://stackblitz.com/edit/linq-single</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*1sK5yCMlOfHxAYhn4yn1iw.png" /></figure><h3>Take</h3><blockquote>Returns a specified number of contiguous elements from the start of a sequence.</blockquote><pre><strong>take(count: number): IEnumerable&lt;T&gt;;</strong></pre><p>This method returns the specified number of records. It is usually used together with the orderBy method.</p><pre>var array = [<br>     {name: &#39;Order 1&#39;, cost: 15233},<br>     {name: &#39;Order 2&#39;, cost: 33533},<br>     {name: &#39;Order 3&#39;, cost: 23511},<br>     {name: &#39;Order 4&#39;, cost: 11244},<br>     {name: &#39;Order 5&#39;, cost: 44432}<br>];</pre><pre>var result = Enumerable.from(array)<br>     .orderBy(o =&gt; o.cost)<br>     .take(2)<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-take">https://stackblitz.com/edit/linq-take</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*A_74N0puXQ34wO0qQYzoPg.png" /></figure><h3>SelectMany</h3><blockquote>Projects each element of a sequence to an <em>IEnumerable&lt;T&gt;</em> and flattens the resulting sequences into one sequence.</blockquote><pre><strong>selectMany&lt;TCollection, TResult&gt;(collectionSelector: (element: T, index: number) =&gt; IEnumerable&lt;TCollection&gt;, resultSelector: (outer: T, inner: TCollection) =&gt; TResult): IEnumerable&lt;TResult&gt;;</strong></pre><p>Let’s show the use with a specific example. We have a collection of orders and each order has a collection of items. It is therefore a collection of items nested in a collection of orders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*oh_RsF-GDka-ve-d9c-Hfg.png" /></figure><p>And you want to combine the collections of items of all orders. SelectMany goes through the individual orders and returns a collection of order items. Finally, it combines all collections of items into one.</p><p>Another illustration of the example in the tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*pKDy27hIXaZLMH25O1RNEw.png" /></figure><p>Now you can tell, if I get a list of items using selectMany, I will lose the order information. SelectMany has another parameter resultSelector: (outer T: inner TCollection) =&gt; TResult. This parameter is a function that returns the current element and the entire input object. In our case, the selected orderItem and the entire order object.</p><p>So, for example, if you want a collection of orderItems of all orders and a specific order name, id, you do so as follows.</p><pre>var result = Enumerable.from(array)<br>    .<strong>selectMany</strong>(m =&gt; m.orderItems, (<strong>order</strong>, result) =&gt; ({<br>         ...result,<br>         <strong>id: order.id,</strong><br>         <strong>name: order.name</strong><br>})).toArray();</pre><p><a href="https://stackblitz.com/edit/linq-selectmany">https://stackblitz.com/edit/linq-selectmany</a></p><p>With this approach, the “left join” operation can be performed as we will show below.</p><h3>Conditions</h3><p>You do not always want to return the entire collection, but specific records.<br>The conditions are just coming. You can use a condition to specify which data set to return.</p><h3>Where</h3><blockquote>Filters a sequence of values based on a predicate.</blockquote><pre><strong>where(predicate: (element: T, index: number) =&gt; boolean): IEnumerable&lt;T&gt;;</strong></pre><p>The most common way for conditional queries is to use the where method. I assume everyone knows the logical operators well. <strong>and</strong> &amp;&amp; a <strong>or</strong> || etc.</p><pre>var result = Enumerable.from(array)<br>    .<strong>where</strong>(w =&gt; w.createdDate &gt;= &#39;2019-11-10&#39; &amp;&amp; w.total &lt; 10000)<br>    .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-where">https://stackblitz.com/edit/linq-where</a></p><h3>Contains</h3><blockquote>Determines whether an element is in the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=netcore-3.1">List&lt;T&gt;</a>.</blockquote><pre><strong>contains(value: T): boolean;</strong></pre><p>Another condition is the contains method. You can use this function to search for a specific list of values. In this example, I’m looking for two specific document numbers.</p><pre>var numbers = [&#39;139976&#39;, &#39;139971&#39;];</pre><pre>var result = Enumerable.from(array)<br>.where(w =&gt; <br>     Enumerable.from(numbers).<strong>contains</strong>(w.documentNumber))<br>.toArray();</pre><p><a href="https://stackblitz.com/edit/linq-contains">https://stackblitz.com/edit/linq-contains</a></p><h3>All</h3><blockquote>Determines whether all elements of a sequence satisfy a condition.</blockquote><pre><strong>all(predicate: (element: T) =&gt; boolean): boolean;</strong></pre><p>The all method returns data only if all elements satisfy the condition specified in the predicate.</p><h3>Any</h3><blockquote>Determines whether any element of a sequence exists or satisfies a condition.</blockquote><pre><strong>any(predicate?: (element: T) =&gt; boolean): boolean;</strong></pre><p>The any method returns data only if no element satisfies the condition specified in the predicate.</p><h3>Distinct</h3><blockquote>Returns distinct elements from a sequence.</blockquote><pre><strong>distinct&lt;TCompare&gt;(compareSelector: (element: T) =&gt; TCompare): IEnumerable&lt;T&gt;;</strong></pre><p>If we have duplicates in the collection that we want to eliminate and always use only the first element of the duplicity, we use the distinct command. When applied to simple data types, the distinct() syntax can be used. However, if it is a complex data type object, we must specifically define what is duplication and what is not.</p><p>distinct data type number:</p><pre>var array = [<br>     1234,<br>     1234,<br>     1555,<br>     1422<br>];</pre><pre>var result = Enumerable.from(array)<br>     .distinct()<br>     .toArray();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*GJ0BPoKrb1Fu-vmt6nok8g.png" /></figure><p>distinct complex type object. Duplicate object can be defined eg by a string. If the string appears more than once, this element is considered a duplicate. The easiest way to generate a string from an object is to convert the record to a JSON string.</p><pre>return Enumerable.from(object)<br>     .distinct(d =&gt; <strong>JSON.stringify(d)</strong>)<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-distinct-object">https://stackblitz.com/edit/linq-distinct-object</a></p><p>I added the Distinct field to make it clear how LINQ decides that it is a duplicate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*VWABBJd6nB9RKpf1IgIggA.png" /></figure><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*SwUHcRraQ2yEH8qLqYVbsA.png" /></figure><h3>Groups</h3><p>Grouping is one of the most powerful capabilities of LINQ. With grouping, you can group data according to selected keys and creates a result value from each group and its key.</p><p>This group is located in a special type of collection named IGrouping &lt;TKey, T&gt;. TKey is the key according to which the group is created and T is the collection of elements that corresponds to the given key.</p><h3>GroupBy</h3><blockquote>Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The elements of each group are projected by using a specified function.</blockquote><pre><strong>groupBy&lt;TKey, TElement, TResult, TCompare&gt;(<br>keySelector: (element: T) =&gt; TKey, <br>elementSelector: (element: T) =&gt; TElement, <br>resultSelector: (key: TKey, element: IEnumerable&lt;TElement&gt;) =&gt; TResult, compareSelector: (element: TKey) =&gt; TCompare): IEnumerable&lt;TResult&gt;;</strong></pre><p>You could say that groupBy is actually the opposite of the selectMany method. Use groupBy to group data according to the specified key. keySelector is a function where fields are defined according to which it will be grouped. What does grouping actually mean? Everything that has the same key, or the specified field in the key, is grouped. elementSelector is a function that describes the resulting group structure. resultSelect is a function that returns a key and a group of type IEnumerable.</p><pre>var array = [<br>     {id: 1, name: &#39;Order 1&#39;, product: &#39;Ford&#39;},<br>     {id: 1, name: &#39;Order 1&#39;, product: &#39;BMW&#39;},<br>     {id: 2, name: &#39;Order 2&#39;, product: &#39;Toyota&#39;},<br>     {id: 2, name: &#39;Order 2&#39;, product: &#39;Skoda&#39;},<br>     {id: 2, name: &#39;Order 2&#39;, product: &#39;Fiat&#39;}<br>];</pre><pre>var result = Enumerable.from(array)<br>     .groupBy(<br>          g =&gt; g.name,<br>          element =&gt; element,<br>          (key, items) =&gt; ({key, items: items.toArray()}<br>     )).toArray();</pre><p><a href="https://stackblitz.com/edit/linq-groupby">https://stackblitz.com/edit/linq-groupby</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*_acdsuvoypdP48aYZJhYaw.png" /></figure><p>In this example, I grouped the data by the name of the order object. For example, if you want to group using multiple fields, the notation is as follows:</p><pre>.groupBy(<br><strong>          g =&gt; ({ g.name, g.id })),</strong><br>          element =&gt; element,<br>          (key, items) =&gt; ({key, items: items.toArray()}<br>     )).toArray();</pre><h3>GroupJoin</h3><blockquote>Correlates the elements of two sequences based on key equality and groups the results.</blockquote><pre><strong>groupJoin&lt;TInner, TKey, TResult&gt;(inner: IEnumerable&lt;TInner&gt;, outerKeySelector: (outer: T) =&gt; TKey, innerKeySelector: (inner: TInner) =&gt; TKey, resultSelector: (outer: T, inner: IEnumerable&lt;TInner&gt;) =&gt; TResult, compareSelector?: (obj: T) =&gt; TKey): IEnumerable&lt;TResult&gt;;</strong></pre><p>An atypical function that has no equivalent in databases. This involves joining a table and grouping at the same time. GroupJoin appends the table according to the primary and foreign keys and then groups this data according to the specified grouping key.</p><pre>var orders = [<br>     {id: 1, name: &#39;Order 1&#39;}<br>];</pre><pre>var orderItems = [<br>     { orderId: 1, product: &#39;Ford&#39; },<br>     { orderId: 1, product: &#39;BMW&#39; }<br>]</pre><pre>var result = Enumerable.from(orders)<br>     .groupJoin(<br>          Enumerable.from(orderItems),<br>          pk =&gt; pk.id,<br>          fk =&gt; fk.orderId,<br>          (order, items) =&gt; ({...order, items: items.toArray()})<br>     ).toArray();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*YYDtPnUxIIGLlRGeBoolvQ.png" /></figure><p><a href="https://stackblitz.com/edit/linq-groupjoin">https://stackblitz.com/edit/linq-groupjoin</a></p><h3>Aggregation functions</h3><blockquote>An aggregation operation computes a single value from a collection of values.</blockquote><pre><strong>min(selector?: (element: T) =&gt; number): number;<br>max(selector?: (element: T) =&gt; number): number;<br>average(selector?: (element: T) =&gt; number): number;    count(predicate?: (element: T, index: number) =&gt; boolean): number;<br>sum(selector?: (element: T) =&gt; number): number;</strong></pre><p>You can apply aggfunc (selector ?: (element: T) =&gt; number): number aggregation functions of the following types to the IEnumerable &lt;T&gt; collection:</p><ul><li><strong>min </strong>— returns the lowest value from the collection</li><li><strong>max </strong>— returns the highest value from the collection</li><li><strong>average </strong>— returns the average values from the collection</li><li><strong>count </strong>— returns the number of elements in the collection</li><li><strong>sum</strong> — returns the sum of elements in the collection</li></ul><pre>var orderItems = [<br>     { orderId: 1, product: &#39;Ford&#39;, cost: 10000 },<br>     { orderId: 1, product: &#39;BMW&#39;, cost: 30000 },<br>     { orderId: 2, product: &#39;Toyota&#39;, cost: 20000 }, <br>     { orderId: 2, product: &#39;Skoda&#39;, cost: 8000 },<br>     { orderId: 2, product: &#39;Fiat&#39;, cost: 6000 }<br>]</pre><pre>var result = Enumerable.from(orderItems)<br>     .groupBy(g =&gt; g.orderId)<br>     .select(s =&gt; ({<br>          orderId: s.key(),<br>          max: s.max(m =&gt; m.cost),<br>          min: s.min(m =&gt; m.cost),<br>          avg: s.average(m =&gt; m.cost),  <br>          count: s.count(),<br>          sum: s.sum(s =&gt; s.cost)<br>}))<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-aggregations">https://stackblitz.com/edit/linq-aggregations</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*zC9rFLGYlOR2tCUg_Gkdcg.png" /></figure><h3>MaxBy, MinBy</h3><pre>maxBy&lt;TKey&gt;(keySelector: (element: T) =&gt; TKey): T; <br>minBy&lt;TKey&gt;(keySelector: (element: T) =&gt; TKey): T;</pre><p>maxBy and minBy are very interesting and useful functions that do not normally occur in LINQ or the database world. It’s actually the same as min and max, but with the difference that the result is not a value but an entire element.</p><pre>const result = Enumerable.from(orders)<br>     .maxBy(s =&gt; s.total);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*_EvShNYJ4a4WErzxP7YPow.png" /></figure><p><a href="https://stackblitz.com/edit/linq-maxby">https://stackblitz.com/edit/linq-maxby</a></p><p>The query looks for the highest value in the column (red column) and returns the entire row (yellow row).</p><h3>Zip</h3><blockquote>Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.</blockquote><pre><strong>zip&lt;U, TResult&gt;(second: IEnumerable&lt;U&gt;, resultSelector: (first: T, second: U, index: number) =&gt; TResult): IEnumerable&lt;TResult&gt;</strong></pre><p>The zip function joins two collections simply according to the order of the items stored in the collection. If the collections do not have the same number of items, the result is the number of records with the least number of items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*qJOVMOsnV7TLvL8dfV5d5w.png" /></figure><p><a href="https://stackblitz.com/edit/linq-zip">https://stackblitz.com/edit/linq-zip</a></p><p>We will use the zip function as we will solve partitioning.</p><h3>Loops</h3><pre><strong>forEach(action: (element: T, index: number) =&gt; void): void;</strong></pre><p>You can use the ForEach command to scroll through the individual elements of an array. With this command you can perform your own action for each record, such as in our case display each item in the log:</p><pre>Enumerable.from(array)<br>          .forEach(f =&gt; console.log(`item ${f}`);</pre><h3>Ordering</h3><pre><strong>orderBy&lt;TKey&gt;(keySelector: (element: T) =&gt; TKey): IOrderedEnumerable&lt;T&gt;;<br>thenBy&lt;TKey&gt;(keySelector: (element: T) =&gt; TKey): IOrderedEnumerable&lt;T&gt;;<br>orderByDescending&lt;TKey&gt;(keySelector: (element: T) =&gt; TKey): IOrderedEnumerable&lt;T&gt;;<br>thenByDescending&lt;TKey&gt;(keySelector: (element: T) =&gt; TKey): IOrderedEnumerable&lt;T&gt;;</strong></pre><p>Have you ever tried to sort javascript? No problem if you sort by one field. And what if you need to sort using multiple fields? With LINQ it can be done really very elegantly.</p><pre>Enumerable.from(array)<br>             .orderByDescending(o =&gt; o.lastname)<br>             .thenBy(o =&gt; o.name)<br>             .thenByDescending(o =&gt; o.age)</pre><p><a href="https://stackblitz.com/edit/linq-ordering">https://stackblitz.com/edit/linq-ordering</a></p><p>It sorts first in descending order by lastname, then in ascending order by name, and last in descending order by age.</p><p>The sort commands are as follows:<br>orderBy — the first command to sort in ascending order<br>orderByDescending — the first command to sort descending<br>thenBy — the following command to sort in ascending order<br>thenByDescending — The following command to sort descending</p><h3>Joining collections</h3><p>Often you will not be enough with just one table, respectively. with one data field. Often in real projects, you will need to join two or more tables together, for example because you are retrieving data from different rest API. And such a reason can be optimization. The volume of data transferred in the two tables can be orders of magnitude smaller than their join on the server side and subsequent transfer to the client. We will show such a real situation below.</p><p>It is a combination of two or more records that have a mutual relationship (common keys)</p><p>There are several types of joins. We will show the most frequently used ones, which will most likely be sufficient for all projects.</p><h3>Relationship with each other</h3><p><strong>1: 1</strong> <strong>OneToOne</strong> — there can be only one specific record from the second table for one record from the first table.<br><strong>1: N</strong> <strong>OneToMany </strong>— there can be several records from the second table for one record from the first table<br><strong>N: N ManyToMany </strong>— that there may be several records from the second table for several records from the first table.</p><h3>Inner Join</h3><blockquote>In relational database terms, an <em>inner join</em> produces a result set in which each element of the first collection appears one time for every matching element in the second collection. If an element in the first collection has no matching elements, it does not appear in the result set.</blockquote><pre><strong>join&lt;TInner, TKey, TResult&gt;(inner: IEnumerable&lt;TInner&gt;, outerKeySelector: (outer: T) =&gt; TKey, innerKeySelector: (inner: TInner) =&gt; TKey, resultSelector: (outer: T, inner: TInner) =&gt; TResult, compareSelector?: (obj: T) =&gt; TKey): IEnumerable&lt;TResult&gt;;</strong></pre><p>An inner join returns data only if the record exists on both sides (collections, tables). If the record is missing on one or the other side, the record will not be returned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*hEVI6PSeeOtLBUdFLnxcGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*vF4n74hqTaXgYAkrN2zVVw.png" /></figure><p>The join command is used to implement an inner join. The join of the left and right collections (tables) is solved using the primary and foreign keys. As soon as a match is found on the left and right, the joined record is returned. E.g. according to the picture. On the left is the primary key Id = 1 and on the right is the foreign key OrderId = 1 pk 1 = fk 1. In this case, two lines are returned, where the left side is repeated according to the lines on the right. This is a type 1: N connection.</p><pre>return Enumerable.from(Orders)<br>     .join(OrderItems, <br>          pk =&gt; pk.id, <br>          fk =&gt; fk.orderId, <br>          (left, right) =&gt; ({...left, ...right}));</pre><p><a href="https://stackblitz.com/edit/linq-inner-join">https://stackblitz.com/edit/linq-inner-join</a></p><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*tnvGjvXOWJyQlWk6Y5u1bg.png" /></figure><h3>Left Join</h3><blockquote>left outer join is a join in which each element of the first collection is returned, regardless of whether it has any correlated elements in the second collection. You can use LINQ to perform a left outer join by calling the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.defaultifempty">DefaultIfEmpty</a> method on the results of a group join.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*JMFCGjLp9uUPLgCqdgl2rA.png" /></figure><p>In practice, the most common case of joining two data sources. This is a join, where a secondary resource joins to a primary resource only if there is a join between the primary and foreign keys. The primary source remains unchanged</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*bcFDVHd5w-C1m4c0Ne5xGw.png" /></figure><p>It is paradoxical that this most common type of joining has no equivalent in javascript, and performing such an operation is not at all a simple topic and often discussed in forums. There are often examples where a single solution is seen by going through the records, which can have a big impact on the performance of the whole system. And that’s what we’re all about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*RtLuNxhIKvSvSLrHneX_Hw.png" /></figure><p>Even with linq.js and linq in C#, it’s no different, and the leftJoin isn’t implemented anywhere. But don’t despair. I will show you how to create your own method that will solve everything for us.</p><p>But first let’s show how to perform a left join using LINQ.</p><pre>const result = Enumerable.from(orders)<br>     .groupJoin(Enumerable.from(orderItems),<br>          pk =&gt; pk.id,<br>          fk =&gt; fk.orderId,<br>          (left, right) =&gt; ({...left, right}))<br>     .selectMany(m =&gt; m.right.defaultIfEmpty(),<br>          (left, right) =&gt; ({...left, ...right}))<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-left-join">https://stackblitz.com/edit/linq-left-join</a></p><p>We have explained groupJoin and selectMany before, so it should not be difficult to understand this syntax. But let’s be honest. Is it readable? Not much :(… never mind.</p><h4>Left join component</h4><p>We can create our own component that will be much more readable.</p><pre>export const <strong>LeftJoin </strong>= (source, inner, pk, fk, result) <br>     =&gt; Enumerable.from(source)<br>             .groupJoin(Enumerable.from(inner),<br>                  s =&gt; pk(s),<br>                  i =&gt; fk(i),<br>                  (left, right) =&gt; ({left, right}))<br>             .selectMany(m =&gt; m.right.defaultIfEmpty(),<br>                  (prev, right) =&gt; result(prev.left, right));</pre><p>I will encapsulate the previous code that performs the left join operation on the LeftJoin method. This is much better. In addition, we will extend Enumerable with a new leftJoin function that can chain functions.</p><pre>Enumerable.prototype.<strong>leftJoin</strong> = function(inner, pk, fk, result) {<br>     return LeftJoin(this, inner, pk, fk, result);<br>}</pre><p>The result can be following:</p><pre><strong>Enumerable.from(orders)<br>     .leftJoin(orderItems,<br>          pk =&gt; pk.id,<br>          fk =&gt; fk.orderId,<br>          (left, right) =&gt; ({...left, ...right}))<br>     .toArray();</strong></pre><p><a href="https://stackblitz.com/edit/linq-left-join-component">https://stackblitz.com/edit/linq-left-join-component</a></p><p>Better? This is much more readable and also shorter notation. Says that it is a combination of two collections using the leftJoin method. There is a clearly defined primary key, foreign key and join left and right collections.</p><h3>Right join</h3><blockquote>right outer join is a join in which each element of the second collection is returned, regardless of whether it has any correlated elements in the first collection. You can use LINQ to perform a right outer join by calling the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.defaultifempty">DefaultIfEmpty</a> method on the results of a group join.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*RkZCdO4dT7ZTwCu6OIzUDA.png" /></figure><p>Right join is the exact opposite of left join. This is a join, where a primary resource joins to a secondary resource only if there is a link between the primary and foreign keys. The secondary source remains unchanged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*VCbCkS7N4-Q5IZ4SvtOeZA.png" /></figure><p>As in the case of leftJoin, there is no rightJoin function in LINQ, so we will write it ourselves using LINQ.</p><pre>export const <strong>RightJoin </strong>= (source, inner, pk, fk, result) <br>  =&gt; Enumerable.from(inner)<br>       .groupJoin(Enumerable.from(source),<br>            i =&gt; fk(i),<br>            s =&gt; pk(s),<br>            (right, left) =&gt; ({right, left}))<br>        .selectMany(<br>            m =&gt; m.left.defaultIfEmpty(),<br>           (prev, left) =&gt; result(left, prev.right));</pre><p>And then we extend Enumerable with the rightJoin function for concatenation.</p><pre>Enumerable.prototype.<strong>rightJoin </strong>= function(inner, pk, fk, result) {<br>     return RightJoin(this, inner, pk, fk, result);<br>}</pre><p>The result can look like this:</p><pre><strong>const result = Enumerable.from(orders)<br>     .rightJoin(Enumerable.from(orderItems),<br>          pk =&gt; pk.id,<br>          fk =&gt; fk.orderId,<br>          (left, right) =&gt; ({...left, ...right})<br>).toArray();</strong></pre><p><a href="https://stackblitz.com/edit/linq-right-join">https://stackblitz.com/edit/linq-right-join</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*8dLe0y5qi4xMMaubeK0xww.png" /></figure><h3>Full outer join</h3><blockquote>The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*jmCPpZEwd9nqjGs5H0um4Q.png" /></figure><p>It basically performs a left join and a right join together. As a result, all records from both the left and right collections are displayed. Again, there is no equivalent in LINQ for calling full outer join, so we write our own component. And as you will see, the full outer join will be a composition from our already created LeftJoin and RightJoin methods.</p><pre>export const <strong>FullOuterJoin </strong>= (source, inner, pk, fk, result) =&gt; {<br>     var left = LeftJoin(source, inner, pk, fk, result);<br>     var right = RightJoin(source, inner, pk, fk, result);<br>     <br>     return left.unionDistinct(right);<br>}</pre><p>And we will extend Enumerable with fullOuterJoin methods</p><pre>Enumerable.prototype.<strong>fullOuterJoin </strong>= function(inner, pk, fk, result) {<br>     return FullOuterJoin(this, inner, pk, fk, result);<br>}</pre><p><a href="https://stackblitz.com/edit/linq-full-outer-join">https://stackblitz.com/edit/linq-full-outer-join</a></p><p>You will also use this method in the merge method. The following example shows the result of joining two collections using a full outer join.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*KTe1E0RyUJmMr0RGyQ6yIQ.png" /></figure><p>Even if the record Id = 3 on the left side does not have the corresponding record on the right side and the record UserId = 4 on the right side does not have the corresponding record on the left side, they will still be in the resulting collection. The result is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*z4fBoLediqKum8Zayg8XBw.png" /></figure><h3>Cross join</h3><blockquote>The cross join produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table if no where clause is used along with cross join.</blockquote><p>The last case of join is where each record from the left collection joins with each record from the right collection. The result is then a collection that has the number of records (left collection * right collection).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*XaeUGj-yx2lUBUAAooEd3g.png" /></figure><p>There is no equivalent for this function in LINQ, but it is easy to use. We apply an inner join where the primary key and the foreign key always return the same value. eg true.</p><pre>export const <strong>CrossJoin </strong>= (source, inner, result) =&gt;<br>     Enumerable.from(source)<br>          .join(Enumerable.from(inner),<br>                pk =&gt; true,<br>                fk =&gt; true,<br>                (left, right) =&gt; result(left, right));</pre><p>And we will extend Enumerable with the crossJoin function.</p><pre>Enumerable.prototype.<strong>crossJoin </strong>= function(inner, result) {<br>     return CrossJoin(this, inner, result);<br>}</pre><p><a href="https://stackblitz.com/edit/linq-cross-join">https://stackblitz.com/edit/linq-cross-join</a></p><p>The result is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*byaNlW_22MtyEjP4iOF73A.png" /></figure><h3>Union</h3><blockquote>Produces the set union of two sequences.</blockquote><pre><strong>union(second: { length: number;[x: number]: T; }): IEnumerable&lt;T&gt;;</strong></pre><p>In LINQ npm, there is only one method for merging two collections, called union. This method simply merges two collections together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*6ee5mDxMXxgsRPBFZiOqsQ.png" /></figure><pre>const result = Enumerable.from(first)<br>     .union(second)<br>     .toArray();</pre><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/177/1*9ob8EVBt6KjOmXf8BUT9Fg.png" /></figure><p><a href="https://stackblitz.com/edit/linq-union">https://stackblitz.com/edit/linq-union</a></p><p>This operation can be replaced by the spread operator in javascript, for example, as follows:</p><pre>const result = [...firstCollection, ...secondCollection];</pre><h3>Union distinct</h3><p>A more interesting function than union would be a function that joins two collections together, but if a record exists in both collections, the process returns only one record.</p><p>The process performs a distinct over the joined collections. viz. following image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*bqeX3M8gNXUQTvKPvUI2ug.png" /></figure><p>There is no such function in LINQ, but we can create our own function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*vUzFwmZ2wKcX6CefwbgQgA.png" /></figure><p><a href="https://stackblitz.com/edit/linq-union-distinct">https://stackblitz.com/edit/linq-union-distinct</a></p><pre>export const <strong>UnionDistinct </strong>= (left, right) =&gt; {<br>     return Enumerable.from(left)<br>          .union(Enumerable.from(right))<br>          .distinct(s =&gt; JSON.stringify(s));<br>}</pre><p>And again we will extend Enumerable with a new function unionDistinct in order to chain functions.</p><pre>Enumerable.prototype.<strong>unionDistinct </strong>= function(right) {<br>     return UnionDistinct(this, right);<br>}</pre><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*9piJaprZAOXYedgzowtLnQ.png" /></figure><pre><strong>const result = Enumerable.from(leftCollection)<br>     .unionDistinct(Enumerable.from(rightCollection)<br>     .toArray();</strong></pre><h3>Except</h3><blockquote>Produces the set difference of two sequences.</blockquote><pre><strong>except&lt;TCompare&gt;(second: IEnumerable&lt;T&gt;, compareSelector: (element: T) =&gt; TCompare): IEnumerable&lt;T&gt;;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*GrnZGyz0vHFEI3JD3OJoPQ.png" /></figure><p>The except method makes a difference to the sets. It basically subtracts the secondary set from the primary set. The result is records from the first collection that do not exist in the second collection.</p><p>Implementation is simple. You take the first collection, you apply the except method with the parameter of the second collection. The second parameter tells which field to compare in terms of duplication.</p><p>In our case, the documentNumber column is compared.</p><pre>const except = Enumerable.from(first)<br>     .<strong>except</strong>(Enumerable.from(second), key =&gt; key.documentNumber)<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-except">https://stackblitz.com/edit/linq-except</a></p><h3>Intersect</h3><blockquote>Produces the set intersection of two sequences.</blockquote><pre><strong>intersect&lt;TCompare&gt;(second: IEnumerable&lt;T&gt;, compareSelector: (element: T) =&gt; TCompare): IEnumerable&lt;T&gt;;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*zfmYagA5e79cg5KK86CjMg.png" /></figure><p>The result is a collection that is both in the first collection and in the second. The use is the same as for the except method. You take the first collection, you apply the intersect method with the parameter of the second collection. The second parameter tells which field to compare in terms of duplication.</p><p><a href="https://stackblitz.com/edit/linq-intersect">https://stackblitz.com/edit/linq-intersect</a></p><pre>const except = Enumerable.from(first)<br>     .<strong>intersect</strong>(Enumerable.from(second), key =&gt; key.documentNumber)<br>     .toArray();</pre><h3>Partition</h3><p><em>Bosses are crazy and have crazy ideas. From the programmer’s point of view of course :)</em></p><p>The boss comes up with the idea that he wants the most expensive order for today. hmm. that’s not a problem.</p><pre>var result = Enumerable.from(orders)<br>     .where(w =&gt; moment(w.createdDate).format(&quot;YYYY.MM.DD&quot;) === &#39;2020.08.01&#39;)<br>     .orderByDescending(o =&gt; o.cost)<br>     .take(1);</pre><p>so return me the most expensive orders for each day. And to make matters worse, return the two most expensive orders for each day</p><p>… How to do it… loop? is this the only solution?</p><p>no, definitely not .. forget the loop … Now comes the partitioning scene. The procedure is as follows:</p><ul><li>First, I group orders by individual days and descending by price.</li><li>then you mark the group’s orders with a serial number descending according to the price</li><li>finally, we select orders by serial number</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*Y4OGco2TnUdrOwg3czmwbA.png" /></figure><pre>return Enumerable.from(orders)<br>     .orderBy(d =&gt; moment(d.createdDate).format(&quot;YYYY.MM.DD&quot;))<br>     .thenByDescending(c =&gt; c.total)<br>     .groupBy(g =&gt; moment(g.createdDate).format(&#39;YYYY.MM.DD&#39;))<br>     .select(group =&gt; ({group, count: group.count()}))<br>     .selectMany(g <br>          =&gt; g.group.zip(Enumerable.range(1, g.count), <br>               (j, i) =&gt; ({...j, [&quot;partition&quot;]: i})))<br>     .where(w =&gt; w.partition &lt;= 2)<br>     .toArray();</pre><p><a href="https://stackblitz.com/edit/linq-partition">https://stackblitz.com/edit/linq-partition</a></p><p>In this case, we will use the zip function to attach the serial number of the group line. However, this is already a more complicated notation, so we put it in the method.</p><pre>export const <strong>PartitionBy </strong>= (grouping, rowNumberPropertyName)<br>=&gt; grouping<br>     .select(group =&gt; ({group, count: group.count()}))<br>     .selectMany(groupWithCount <br>     =&gt; groupWithCount.group.zip(<br>          Enumerable.range(1, groupWithCount.count),<br>          (j, i) =&gt; ({...j, [rowNumberPropertyName]: i})));</pre><p>and we will extend Enumerable with the partitionBy method with which we will be able to chain queries.</p><pre>Enumerable.prototype.<strong>partitionBy </strong>= function(rowNumberPropertyName) {<br>     return PartitionBy(this, rowNumberPropertyName);<br>}</pre><p>and we apply our example to the just created component</p><pre><strong>return Enumerable.from(orders)<br>    .orderBy(d =&gt; moment(d.createdDate).format(&#39;YYYY.MM.DD&#39;))<br>    .thenByDescending(c =&gt; c.total)<br>    .groupBy(g =&gt; moment(g.createdDate).format(&#39;YYYY.MM.DD&#39;)<br>    .partitionBy(&quot;partition&quot;)<br>    .where(w =&gt; w.partition &lt;= 2);</strong></pre><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*xI0sb8KIBdyXRvB_jZ0Mrw.png" /></figure><h3>Pivot</h3><blockquote><em>PIVOT</em> rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output. And <em>PIVOT</em> runs aggregations where they&#39;re required on any remaining column values that are wanted in the final output.</blockquote><p>You will definitely be dealing with a situation where you need to display the data you have stored in a row in a column. This method of rotating rows into columns is called a pivot. Typical examples are orders and products. The source data is stored in a row as shown in the following figure. Both order number and product code with quantity.</p><p>The resulting collection looks like product codes in a row and orders in a column. The columns will therefore be dynamic and there will be as many orders as there are orders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*3YHC7LfL_GJM-iQbNzWcbQ.png" /></figure><p>The pivot function is characterized by the fact that the data in both the row and the column are grouped. As can be seen from the left picture, Ford repeats twice, but on the right side is ford only once. The same in the column with orderId 1. This means that the values (cost) are collections of type IEnumerable &lt;T&gt;. So you can apply aggregation functions to them. But it’s up to you what you display in the value, it doesn’t have to be just an aggregation of values, but you can easily display a list of values in a row, etc ..</p><p>Since LINQ has no pivot function, we will write it using LINQ.</p><pre>export const <strong>Pivot </strong>= (source, columnSelector, rowSelector, rowPropertyName, dataSelector)<br>=&gt; {<br>  var columns = Enumerable<br>     .from(source)<br>     .select(columnSelector)<br>     .distinct();</pre><pre>var cols = Enumerable<br>     .from([rowPropertyName])<br>     .concat(columns.select(s =&gt; s));</pre><pre>var rows = Enumerable<br>     .from(source)<br>     .groupBy(rowSelector)<br>     .select(rowGroup =&gt; {<br>       var values = columns.groupJoin(<br>         rowGroup, <br>         c =&gt; c, <br>         r =&gt; columnSelector(r), <br>         (c, columnGroup) =&gt; dataSelector(columnGroup));</pre><pre>return {<br>         key: rowGroup.key(),<br>         values: [rowGroup.key(), ...values.toArray()]<br>       };<br>     }).toArray();</pre><pre>var dics = Enumerable<br>    .from(rows)<br>    .select(s =&gt; {<br>      var result = {};<br>      cols.zip(s.values, (k, v) =&gt; ({k, v}))<br>          .forEach(s =&gt; {result = {...result, [s.k]: s.v}});<br>      return result;<br>  }, {});</pre><pre>return dics;<br>}</pre><p>Before we get to the detailed description of this function, we must explain the individual input parameters:</p><ul><li><strong>source</strong> — source data.</li><li><strong>columnSelector</strong> (red) — is a function that describes how to display column,</li><li><strong>datarowSelector</strong> (green) — is a function that describes how to display data in a row,</li><li><strong>rowPropertyName</strong> (blue) — is the name of the first column of rowSelector,</li><li><strong>dataSelector</strong> (yellow) — is a function that describes the display of individual values.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*eqEQuCii41OqJzasT1g-9w.png" /></figure><p>And a new method in Enumerable</p><pre>Enumerable.prototype.<strong>pivot </strong>= function(columnSelector, rowSelector, rowPropertyName, dataSelector) {<br>    return Pivot(this, columnSelector, rowSelector, rowPropertyName, dataSelector);<br>}</pre><p>Using our function, you can create a pivot from source data that is simple and readable.</p><pre><strong>const result = Enumerable.from(orderItems)<br>     .pivot(<br>          columnSelector =&gt; `orderId:${columnSelector.orderId}`,<br>          rowSelector =&gt; rowSelector.product,<br>          &quot;Product&quot;, <br>          dataSelector =&gt; dataSelector.sum(s =&gt; s.cost)<br>     ).toArray();</strong></pre><p><a href="https://stackblitz.com/edit/linq-pivot">https://stackblitz.com/edit/linq-pivot</a></p><h3>Merge</h3><blockquote>Merge the specified collection with the current collection.</blockquote><p>Imagine a situation where you have a list of orders. And suddenly you get a list of corrected and new orders. How easy is it to update existing orders and assign new orders? There is nothing simple in javascript. So we will write our own component that will solve it for us. It won’t be complicated at all. But we will use our components, which we have created so far.</p><h4>How to do it?</h4><p>I take a list of original orders and attach to them (using the full outer join method) a list of new or changed orders. Full outer join because we need both records from the left part of the collection (original collection) and records from the right part (new collection) on the output. How the original and new collections will be merged:</p><ul><li>i will return the right side record,</li><li>if there is no record on the right side (new collection) then I will return the left side (original collection).</li></ul><p>I’ll just show it in the picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U2uUJ6jyChR9HahiYK9K7A.png" /></figure><pre>var result = Enumerable.from(orders)<br>     .fullOuterJoin(newOrders,<br>          pk =&gt; pk.documentNumber,<br>          fk =&gt; fk.documentNumber,<br>          (left, right) =&gt; (right || left))</pre><p>To make it even more readable, we wrap all the functionality in a function</p><pre>const <strong>Merge </strong>= (source, inner, pk, fk, result)<br>     =&gt; Enumerable.from(source).fullOuterJoin(<br>          Enumerable.from(inner),<br>          s =&gt; pk(s),<br>          i =&gt; fk(i),<br>          (left, right) =&gt; result(left, right));</pre><p>And again we extend the functionality Enumerable a new function merge in order to chaining.</p><pre>Enumerable.prototype.<strong>merge </strong>= function(inner, pk, fk, result) {<br>     return Merge(this, inner, pk, fk, result);<br>}</pre><p>Calling the merge function is really simple and readable:</p><pre><strong>Enumerable.from(orders)<br>     .merge(newOrders, <br>          pk =&gt; pk.documentNumber, <br>          fk =&gt; fk.documentNumber, <br>          (left, right) =&gt; ({...left, ...right}));</strong></pre><p>the result is as follows. Document Number 140710 has been updated and document number 139617 has been added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*-4mln9IXMgd7l3jlka4Prw.png" /></figure><p><a href="https://stackblitz.com/edit/linq-merge">https://stackblitz.com/edit/linq-merge</a></p><h3>Denormalize</h3><p>Everyone tries to write code to match the specified patterns, to follow all the rules, not to duplicate the code, etc. Unfortunately, not everything is as you imagine, and sometimes it is necessary to denormalize the code. Mainly for optimization purposes. Someone just can’t avoid denormalization. Although it may be less readable, non-standard, but it can be much faster, it can load data faster, response responses can be faster, and so on.</p><p>Imagine a situation where we need to return 100,000 orders with all the details, such as currency, supplier detail, product detail, unit, etc., and display them as items, ie. one line = one order item.</p><p>The first thing that occurs to me is that I use the functionality that returns the detail of one order and I apply all 100,000 orders to it. Ideal situation. The code is not duplicated and everything works as it should.</p><p>The problem occurs when the customer wants to retrieve this data set and waits for the result for 2 minutes because a huge amount of data is being transmitted.</p><p>We also got into a similar problem and we finally managed to transfer the data in the order of seconds. And here comes the code denormalization. I will describe specifically one of the many cases of denormalization that could be applied. Don’t take it as a consensus that everything should be done this way. This is really just one specific case out of many, which can also be solved in various ways.</p><p>Let’s take a deep look at it. The detail of one order item could look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*i4NC5Av615MGxznE_T89Uw.png" /></figure><p>Pretty much data, right? Couldn’t it be optimized? Of course. I will not focus on element names (documentItems will be repeated many thousands of times, so such an element could be rewritten to di). We will be mainly interested in duplicate data.</p><p>Elements such as client, supplier, currency, product, unit will be repeated many times. And they are not small data. Therefore, we will send a bulk list of clients, suppliers, product and currencies, and in orders we will refer to them only by id. Then such denormalized data could look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*DwpndOwIBc8yPKGH8uccEw.png" /></figure><p>We already have denormalized data and we transfer an order of magnitude smaller amount of data. In our case, there can be a reduction of up to 50%. Now I will show you how to connect such data and display it in a table structure for the grid.</p><p>Because the result will be individual items of orders, the first thing we will start with is that we display a list of all items of all orders in one table.</p><pre>const result = Enumerable.from(denormalize)<br>     .selectMany(m =&gt; m.documentItems, <br>          (all, item) =&gt; ({...item, all }))</pre><p>Now I will use leftJoin to join other objects.</p><pre>.leftJoin(Enumerable.from(clients),<br>     left =&gt; left.all.clientId,<br>     right =&gt; right.id,<br>     (left, client) =&gt; ({...left, client}))</pre><pre>.leftJoin(Enumerable.from(suppliers),<br>     left =&gt; left.all.supplierId,<br>     right =&gt; right.id,<br>     (left, supplier) =&gt; ({...left, supplier}))</pre><pre>.leftJoin(Enumerable.from(products),<br>     left =&gt; left.productId,<br>     right =&gt; right.id,<br>     (left, product) =&gt; ({...left, product}))</pre><p>Finally, I display this structured data in one table so that it can be displayed in a grid.</p><pre>.select(item =&gt; ({<br>     id: item.id,<br>     clientCode: item.client.code,<br>     clientName: item.client.name,<br>     supplierCode: item.supplier.code,<br>     supplierName: item.supplier.name,<br>     supplierAddress: item.supplier.address,<br>     currencyCode: item.currency.code,<br>     code: item.product.code,<br>     productName: item.product.name,<br>     unit: item.product.unit,<br>     description: item.description,<br>     quantity: item.quantity,<br>     cost: item.cost,<br>     createdDate: item.createdDate<br>}));</pre><p><a href="https://stackblitz.com/edit/linq-denormalize">https://stackblitz.com/edit/linq-denormalize</a></p><p>The result can be the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-j18qiUGtxe3YUn8sjeh4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*ANyrOHD7NHd9JMfGD5SgkQ.png" /></figure><p>This was a demonstration I wanted to show how well LINQ can be used to format data.</p><h3>Conclusion</h3><p>LINQ is a great technology, thanks to which you can easily manipulate data and I believe that you will stay true to this technology forever. When I learned that it also exists in the javascript version, I already had a lot of experience with LINQ in C #. But for javascript programmers, the documentation is really sparse, almost non-existent. That’s why I decided to write this comprehensive article to help them and solve most common questions.</p><p>Thank you for every like you give me. It gives me the strength to go on and create other interesting articles, and the feeling that what I’m doing makes at least a little sense.</p><p>If you like this article and it helps you, you can buy me coffee. I love coffee👍</p><figure><a href="https://www.buymeacoffee.com/hlouzek"><img alt="" src="https://cdn-images-1.medium.com/max/289/1*Tvx8QQ255eAQG9cNlfJr_w.png" /></a></figure><blockquote>I would like to apologize for the grammar mistakes that will certainly appear in the text. I’m not an English speaking person. But I believe that you will forgive me for these shortcomings, because this article is not about grammar, but about the technical values that are contained in the article.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3759e00aceb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/data-manipulation-in-javascript-using-linq-f3759e00aceb">Data Manipulation in JavaScript Using LINQ</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best data grid in javascript, react, angular and vue]]></title>
            <link>https://medium.com/swlh/best-data-grid-in-javascript-react-angular-and-vue-d27997153a2?source=rss-37b6fb9ad0ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/d27997153a2</guid>
            <category><![CDATA[datagrid]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ondrej Hlouzek]]></dc:creator>
            <pubDate>Sat, 11 Jul 2020 21:50:39 GMT</pubDate>
            <atom:updated>2020-07-11T21:50:39.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U2dnCMk_RXVevwec" /><figcaption>Photo by <a href="https://unsplash.com/@austindistel?utm_source=medium&amp;utm_medium=referral">Austin Distel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Are you looking for the best grid for your project, which would provide you with all possible and impossible functions that would satisfy even a demanding client? and which can be implemented in javascript, angular, react or vue?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mi5WVYPJAteDJiyig7hR1g.png" /></figure><p>Are you looking for and deciding for a long time between a bunch of different more advanced and less successful projects and you can’t choose? Is there always something missing from each grid or is it implemented so that it does not suit you?</p><p>So you are in the same situation as us a year ago, when we were deciding which data grid would really be the best and we didn’t find out, for a week, a month, that such a grid couldn’t be used in our case?</p><p>Welcome to a situation like ours.</p><p>This is not an advertisement for any data grid. I’m a regular programmer, just like you, and I’ve gotten into the same situation as you. And I want to save you long nights and weeks by choosing the best.</p><p>We tried different variants, which we implemented for weeks, and in the end we had to give them up. We also tried to create our own set. :) rule number one, do not invent the wheel!</p><p>The best is, in our experience, <a href="https://www.ag-grid.com/"><strong>ag-grid</strong></a>.</p><figure><img alt="ag-grid" src="https://cdn-images-1.medium.com/max/225/1*jsAaY5oRAW042Iws9aYT0w.png" /></figure><p>Everything it offers in the free version will definitely suffice for the vast majority of projects. It offers a really inexhaustible number of functions. If you still need to use the features that are part of the paid version, you can put a little effort into solving the self-help. If a customer requires features that are in the paid version, then I believe that such a customer will have no problem paying extra for the paid version.</p><p>The huge advantage of ag-agrid is a really brilliantly executed documentation, which really everyone will understand, with a large number of demonstrations. During the whole period of use, we did not get into a situation where this grid could not do what I wanted. So you really don’t have to worry that after weeks of programming you will have to rewrite the whole project, because the grid is missing some function.</p><p>If the already extensive documentation cannot answer your questions, there is a large community of programmers who have certainly solved your problem in the past.</p><p>Probable main requirements for such a grid?</p><ol><li>ability to load large amounts of data. Tens of thousands and hundreds of thousands of records. Not a problem.</li><li>nice and clean graphic processing and themes.</li><li>absolute reliability and speed</li><li>sort by multiple columns</li><li>possibility to extend functionality with own components</li><li>easy work with colors, styles</li><li>pivot, grouping with sorting</li><li>detailed documentation with many examples</li><li>large community of programmers</li></ol><p>This article is not about describing all the features. You can find out in the documentation. The goal is to help you choose a grid that will not disappoint you and save you a lot of time, and I believe that ag-grid will offer you everything you need.</p><p>But nothing is perfect. During the year of use, we did not find any defects or shortcomings. We are missing the following:</p><ul><li>the zoom out function, which we would appreciate in the mobile version, but could be implemented with a little effort</li><li>in the mobile version, you can’t simply select cells</li></ul><p>How to begin? Let’s try to run the first grid in the react application on a few lines of code.</p><p>install npm packages</p><pre>npm install ag-grid-community<br>npm install ag-grid-react</pre><p>choose and import specific cascading styles. eg balham,</p><pre>import &quot;ag-grid-community/dist/styles/ag-grid.css&quot;;<br>import &quot;ag-grid-community/dist/styles/ag-theme-balham.css&quot;;</pre><p>import AgGridReact from the ag-grid-react package. Embed the entire grid in a div tag with the ag-grid-balham style applied.</p><p>To load the grid, insert a data collection into the rowData property. columnDefs contains column definitions. domLayout sets the automatic grid height according to the amount of data.</p><pre>import {AgGridReact} from ‘ag-grid-react’;</pre><pre>const columnDefs = [  <br>  {headerName: &quot;Id&quot;, field: &quot;id&quot;, width: 50},<br>  {headerName: &quot;Name&quot;, field: &quot;name&quot;, width: 70},<br>  {headerName: &quot;Product&quot;, field: &quot;product&quot;, width: 80},<br>  {headerName: &quot;Cost&quot;, field: &quot;cost&quot;, width: 60}<br>];</pre><pre> <br>&lt;div className=&quot;ag-theme-balham&quot;&gt;<br>  &lt;AgGridReact<br>     columnDefs={columnDefs}<br>     rowData={data}<br>     domLayout=&quot;autoHeight&quot;<br>  /&gt;<br>&lt;/div&gt;</pre><p><a href="https://stackblitz.com/edit/best-grid">https://stackblitz.com/edit/best-grid</a></p><h3>Conclusion</h3><p>There are a number of differently successful grids on the Internet that you can apply to your projects. If you do not have the time and desire to go through all these grids and you are looking for a quality grid that contains all the necessary functions, ag-grid is, in our experience, number one.</p><p>Happy coding!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E7r47nGvPeBtDDnW" /><figcaption>Photo by <a href="https://unsplash.com/@nullplus?utm_source=medium&amp;utm_medium=referral">Razvan Chisu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d27997153a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/best-data-grid-in-javascript-react-angular-and-vue-d27997153a2">Best data grid in javascript, react, angular and vue</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>