並べ替え

このサンプルでは、コメントコンポーネント初期化時に読み込まれるコメントの並べ替えを設定しています。更新日時の降順で全てのコメントが並べ替えられることを確認することができます。

コメントコンポーネントの並べ替え機能について解説します。 並べ替え コメントコンポーネントは、「投稿日時」「更新日時」「返信数」「リアクション数」での並べ替えを提供しています。デフォルトでは並べ替えを設定しません。 sortInfoインターフェースを利用して、並べ替え項目と昇順/降順を指定できます。 sortByプロパティを利用して、並べ替えの項目を設定できます。sortByプロパティには、GcCommentSortBy列挙体の次の値を設定することができます。 GcCommentSortByの値 説明 PostTime 投稿日時 UpdateTime 更新日時 RepliesCount 返信数 ReactionsCount リアクション数 Default 並べ替えを設定しない また、isDescプロパティを利用して、ソート順を指定できます。デフォルトはtrue、降順で並べ替えられます。 設定例は以下の通りです。 並べ替えのドロップダウンリスト 上記、コメントコンポーネントが提供している「デフォルト」「投稿日時」「更新日時」「返信数」「リアクション数」の並べ替えは、ヘッダーに表示されたドロップダウンリストからも実行できます。
<template> <div> <GcCommentComponent :openLinkMode="GC.InputMan.OpenLinkMode.GoToComment" :sortInfo="sortInfo" :userInfo="userInfo" :loadComments="loadComments" :header="header" :editorConfig="editorConfig" ></GcCommentComponent> </div> </template> <script setup> import '@mescius/inputman.comment/CSS/gc.inputman.comment.css'; import '@mescius/inputman.comment.vue'; import { GcCommentComponent } from '@mescius/inputman.comment.vue'; import * as GC from '@mescius/inputman.comment'; import "@mescius/inputman.richtexteditor/CSS/gc.inputman.richtexteditor.css"; import * as RichTextEditorControl from "@mescius/inputman.richtexteditor"; import "@mescius/inputman.richtexteditor/JS/plugins/all"; import { postedComments } from './data.js'; import './styles.css'; const sortInfo = { isDesc: true, sortBy: GC.InputMan.GcCommentSortBy.UpdateTime, }; const userInfo = { id: '1', name: '森上 偉久馬', avatar: '$IMDEMOROOT$/ja/samples/comment/sort/img/avatar1.png', }; const loadComments = () => { return { comments: postedComments }; }; const editorConfig = { editorType: GC.InputMan.GcCommentEditorType.GcRichTextEditor, plugins: [RichTextEditorControl.InputMan.GcRichTextEditorPluginItem.All], height: 150, menubar: [], toolbar: [ RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.ForeColor, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.BulList, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.NumList, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Indent, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Outdent, ] } const header = [GC.InputMan.GcCommentHeaderFooterItem.Sort]; </script>
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content="コメントコンポーネント 使い方" lang="ja" xml:lang="ja" /> <title>コメントコンポーネント - 並べ替え</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script src="compiler.js" type="module"></script> <script> window.onload = function() { var System = SystemJS; System.import("./src/app.js"); } </script> </head> <body> <div id="app"></div> </body> </html>
export const postedComments = [ { id: '1', userInfo: { id: '1', name: '森上 偉久馬', avatar: '$IMDEMOROOT$/ja/samples/comment/sort/img/avatar1.png', }, content: 'このサンプルではコメントを更新日付の降順で並べ替えています。', postTime: new Date(2024, 7, 18, 8, 1, 50), updateTime: new Date(2024, 8, 18, 8, 1, 50), reactions: [ { reactionChar: '👍', count: 4, }, ], }, { id: '2', userInfo: { id: '3', name: '加藤 泰江', avatar: '$IMDEMOROOT$/ja/samples/comment/sort/img/avatar3.png', }, content: 'デフォルトではコメントIDを昇順で並べています。', postTime: new Date(2024, 6, 20, 8, 1, 1), updateTime: new Date(2024, 7, 20, 8, 1, 1), reactions: [ { reactionChar: '👍', count: 2, currentUserReacted: true, }, ], }, { id: '3', userInfo: { id: '5', name: '松沢 誠一', avatar: '$IMDEMOROOT$/ja/samples/comment/sort/img/avatar5.png', }, content: '必要に応じて、並べ替えの項目を投稿日時/更新日時/返信数/リアクション数に変更できます。', postTime: new Date(2024, 6, 16, 8, 1, 59), updateTime: new Date(2024, 5, 16, 8, 1, 59), }, { id: '4', userInfo: { id: '6', name: '成宮 真紀', avatar: '$IMDEMOROOT$/ja/samples/comment/sort/img/avatar6.png', }, content: 'もちろんヘッダーに表示されたソートダイアログから並べ替えられます。', postTime: new Date(2024, 4, 1, 8, 0, 0), updateTime: new Date(2024, 5, 1, 8, 0, 0), reactions: [ { reactionChar: '👍', count: 3, currentUserReacted: true, }, ], }, { id: '5', userInfo: { id: '6', name: '成宮 真紀', avatar: '$IMDEMOROOT$/ja/samples/comment/sort/img/avatar6.png', }, content: '昇順または降順にも変更できますね。', postTime: new Date(2024, 6, 20, 8, 1, 1), updateTime: new Date(2024, 7, 20, 8, 1, 1), parentCommentId: '2', }, ];
body { box-sizing: content-box !important; height: 551px !important; }
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { 'vue': "npm:vue/dist/vue.esm-browser.js", 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', "systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js", "@mescius/inputman": 'npm:@mescius/inputman/index.js', "@mescius/inputman.vue": 'npm:@mescius/inputman.vue/lib/gc.inputman.plugin.vue.js', "@mescius/inputman/CSS": "npm:@mescius/inputman/CSS", "@mescius/inputman.richtexteditor": "npm:@mescius/inputman.richtexteditor/index.js", "@mescius/inputman.richtexteditor.vue": "npm:/@mescius/inputman.richtexteditor.vue/lib/gc.inputman.richtexteditor.plugin.vue.js", "@mescius/inputman.richtexteditor/CSS": "npm:@mescius/inputman.richtexteditor/CSS", '@mescius/inputman.richtexteditor/JS/plugins/advlist': 'npm:@mescius/inputman.richtexteditor/JS/plugins/advlist/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/all': 'npm:@mescius/inputman.richtexteditor/JS/plugins/all/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/autosave': 'npm:@mescius/inputman.richtexteditor/JS/plugins/autosave/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/charmap': 'npm:@mescius/inputman.richtexteditor/JS/plugins/charmap/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/directionality': 'npm:@mescius/inputman.richtexteditor/JS/plugins/directionality/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/emoticons': 'npm:@mescius/inputman.richtexteditor/JS/plugins/emoticons/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/fullscreen': 'npm:@mescius/inputman.richtexteditor/JS/plugins/fullscreen/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/htmlcode': 'npm:@mescius/inputman.richtexteditor/JS/plugins/htmlcode/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/image': 'npm:@mescius/inputman.richtexteditor/JS/plugins/image/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/link': 'npm:@mescius/inputman.richtexteditor/JS/plugins/link/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/lists': 'npm:@mescius/inputman.richtexteditor/JS/plugins/lists/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/media': 'npm:@mescius/inputman.richtexteditor/JS/plugins/media/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/pagebreak': 'npm:@mescius/inputman.richtexteditor/JS/plugins/pagebreak/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/preview': 'npm:@mescius/inputman.richtexteditor/JS/plugins/preview/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/save': 'npm:@mescius/inputman.richtexteditor/JS/plugins/save/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/searchreplace': 'npm:@mescius/inputman.richtexteditor/JS/plugins/searchreplace/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/table': 'npm:@mescius/inputman.richtexteditor/JS/plugins/table/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/template': 'npm:@mescius/inputman.richtexteditor/JS/plugins/template/plugin.js', '@mescius/inputman.richtexteditor/JS/plugins/wordcount': 'npm:@mescius/inputman.richtexteditor/JS/plugins/wordcount/plugin.js', "@mescius/inputman.comment": 'npm:@mescius/inputman.comment/index.js', "@mescius/inputman.comment.vue": 'npm:@mescius/inputman.comment.vue/lib/gc.inputman.comment.plugin.vue.js', "@mescius/inputman.comment/CSS": "npm:@mescius/inputman.comment/CSS", '@mescius/wijmo': 'npm:@mescius/wijmo/index.js', '@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles', '@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures/wijmo.culture.ja.js', '@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js', '@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js', '@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js', '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js', '@mescius/spread-sheets/styles': 'npm:@mescius/spread-sheets/styles', 'css': 'npm:systemjs-plugin-css/css.js', }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);