angular service for centralizing common grid functions The 2019 Stack Overflow Developer Survey Results Are InAngularJS bookviewer directive written with Typescript and Angular-ui bootstrapReusable REST service class for Angular2 in TypeScriptModal component in Angular 2Vehicle price calculation Angular serviceAngular + Redux app organization and initialization: transfer from a PHP-driven websiteCalling Service and Initiate under ngOnOnit (not in Constructor) Hook in Angular4Build dynamic HTTP service with AngularAngular2 “Logged In State Watcher”Search Result with infinite scroll React componentOptimistic validation on tab change

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

Pokemon Turn Based battle (Python)

Why “相同意思的词” is called “同义词” instead of "同意词"?

How to obtain a position of last non-zero element

Can a flute soloist sit?

What do I do when my TA workload is more than expected?

Why didn't the Event Horizon Telescope team mention Sagittarius A*?

Is Cinnamon a desktop environment or a window manager? (Or both?)

How to type a long/em dash `—`

Relationship between Gromov-Witten and Taubes' Gromov invariant

What do these terms in Caesar's Gallic wars mean?

If a sorcerer casts the Banishment spell on a PC while in Avernus, does the PC return to their home plane?

How much of the clove should I use when using big garlic heads?

What is the motivation for a law requiring 2 parties to consent for recording a conversation

How to charge AirPods to keep battery healthy?

Cooking pasta in a water boiler

Worn-tile Scrabble

Is it possible for absolutely everyone to attain enlightenment?

If I can cast sorceries at instant speed, can I use sorcery-speed activated abilities at instant speed?

Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Why not take a picture of a closer black hole?

Slides for 30 min~1 hr Skype tenure track application interview

How to translate "being like"?



angular service for centralizing common grid functions



The 2019 Stack Overflow Developer Survey Results Are InAngularJS bookviewer directive written with Typescript and Angular-ui bootstrapReusable REST service class for Angular2 in TypeScriptModal component in Angular 2Vehicle price calculation Angular serviceAngular + Redux app organization and initialization: transfer from a PHP-driven websiteCalling Service and Initiate under ngOnOnit (not in Constructor) Hook in Angular4Build dynamic HTTP service with AngularAngular2 “Logged In State Watcher”Search Result with infinite scroll React componentOptimistic validation on tab change



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1












$begingroup$


I have an angular 7 app that is data focused and as a result has dozens of grids. These grids are from the Kendo UI for ANgular component library made by Telerik. These grid components expose hooks for the sort, filter, group functions of the grid. 90% of the grids I have are a very simple CRUD grid with next to no validation or business logic involved.



As a result, I have to write the following code (Typescript) over and over for each grid:



 public initData(): void 
this.gridData = process(this.data, this.gridState);


public onStateChange(state: DataStateChangeEvent): void
state.group.map(group => (group.aggregates = this.aggregates));
this.gridState = state;
this.gridData = process(this.data, this.gridState);


public groupChange(grp: GroupDescriptor[]): void
this.groups = grp;
this.gridData = process(this.data, this.gridState);


public sortChange(srt: SortDescriptor[]): void
this.sort = srt;
this.gridData = process(this.data, this.gridState);


public filterChange(fltr: CompositeFilterDescriptor): void
this.filter = fltr;
this.gridData = process(filterBy(this.data, this.filter),
group: this.groups,
sort: this.sort
);



this is obviously in the component class behind each grid.



What I am wondering is, Can I move the functions to a service so that I don't have to rewrite them for each component? Additionally, should I create them as static so that there is only one or should I instantiate a new "service" for each component?



Just wondering what others think about this



Thanks










share|improve this question









$endgroup$


















    1












    $begingroup$


    I have an angular 7 app that is data focused and as a result has dozens of grids. These grids are from the Kendo UI for ANgular component library made by Telerik. These grid components expose hooks for the sort, filter, group functions of the grid. 90% of the grids I have are a very simple CRUD grid with next to no validation or business logic involved.



    As a result, I have to write the following code (Typescript) over and over for each grid:



     public initData(): void 
    this.gridData = process(this.data, this.gridState);


    public onStateChange(state: DataStateChangeEvent): void
    state.group.map(group => (group.aggregates = this.aggregates));
    this.gridState = state;
    this.gridData = process(this.data, this.gridState);


    public groupChange(grp: GroupDescriptor[]): void
    this.groups = grp;
    this.gridData = process(this.data, this.gridState);


    public sortChange(srt: SortDescriptor[]): void
    this.sort = srt;
    this.gridData = process(this.data, this.gridState);


    public filterChange(fltr: CompositeFilterDescriptor): void
    this.filter = fltr;
    this.gridData = process(filterBy(this.data, this.filter),
    group: this.groups,
    sort: this.sort
    );



    this is obviously in the component class behind each grid.



    What I am wondering is, Can I move the functions to a service so that I don't have to rewrite them for each component? Additionally, should I create them as static so that there is only one or should I instantiate a new "service" for each component?



    Just wondering what others think about this



    Thanks










    share|improve this question









    $endgroup$














      1












      1








      1





      $begingroup$


      I have an angular 7 app that is data focused and as a result has dozens of grids. These grids are from the Kendo UI for ANgular component library made by Telerik. These grid components expose hooks for the sort, filter, group functions of the grid. 90% of the grids I have are a very simple CRUD grid with next to no validation or business logic involved.



      As a result, I have to write the following code (Typescript) over and over for each grid:



       public initData(): void 
      this.gridData = process(this.data, this.gridState);


      public onStateChange(state: DataStateChangeEvent): void
      state.group.map(group => (group.aggregates = this.aggregates));
      this.gridState = state;
      this.gridData = process(this.data, this.gridState);


      public groupChange(grp: GroupDescriptor[]): void
      this.groups = grp;
      this.gridData = process(this.data, this.gridState);


      public sortChange(srt: SortDescriptor[]): void
      this.sort = srt;
      this.gridData = process(this.data, this.gridState);


      public filterChange(fltr: CompositeFilterDescriptor): void
      this.filter = fltr;
      this.gridData = process(filterBy(this.data, this.filter),
      group: this.groups,
      sort: this.sort
      );



      this is obviously in the component class behind each grid.



      What I am wondering is, Can I move the functions to a service so that I don't have to rewrite them for each component? Additionally, should I create them as static so that there is only one or should I instantiate a new "service" for each component?



      Just wondering what others think about this



      Thanks










      share|improve this question









      $endgroup$




      I have an angular 7 app that is data focused and as a result has dozens of grids. These grids are from the Kendo UI for ANgular component library made by Telerik. These grid components expose hooks for the sort, filter, group functions of the grid. 90% of the grids I have are a very simple CRUD grid with next to no validation or business logic involved.



      As a result, I have to write the following code (Typescript) over and over for each grid:



       public initData(): void 
      this.gridData = process(this.data, this.gridState);


      public onStateChange(state: DataStateChangeEvent): void
      state.group.map(group => (group.aggregates = this.aggregates));
      this.gridState = state;
      this.gridData = process(this.data, this.gridState);


      public groupChange(grp: GroupDescriptor[]): void
      this.groups = grp;
      this.gridData = process(this.data, this.gridState);


      public sortChange(srt: SortDescriptor[]): void
      this.sort = srt;
      this.gridData = process(this.data, this.gridState);


      public filterChange(fltr: CompositeFilterDescriptor): void
      this.filter = fltr;
      this.gridData = process(filterBy(this.data, this.filter),
      group: this.groups,
      sort: this.sort
      );



      this is obviously in the component class behind each grid.



      What I am wondering is, Can I move the functions to a service so that I don't have to rewrite them for each component? Additionally, should I create them as static so that there is only one or should I instantiate a new "service" for each component?



      Just wondering what others think about this



      Thanks







      typescript angular-2+






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      J KingJ King

      1455




      1455




















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217286%2fangular-service-for-centralizing-common-grid-functions%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217286%2fangular-service-for-centralizing-common-grid-functions%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订