How to group records when rendering in HTML The 2019 Stack Overflow Developer Survey Results Are InHow do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How to decide when to use Node.js?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?

Is flight data recorder erased after every flight?

How come people say “Would of”?

How to reverse every other sublist of a list?

Realistic Alternatives to Dust: What Else Could Feed a Plankton Bloom?

Is there a name of the flying bionic bird?

Why do some words that are not inflected have an umlaut?

How long do I have to send my income tax payment to the IRS?

What tool would a Roman-age civilization have to grind silver and other metals into dust?

Protecting Dualbooting Windows from dangerous code (like rm -rf)

Patience, young "Padovan"

Deadlock Graph and Interpretation, solution to avoid

What do hard-Brexiteers want with respect to the Irish border?

Should I write numbers in words or as numerals when there are multiple next to each other?

Time travel alters history but people keep saying nothing's changed

Why did Howard Stark use all the Vibranium they had on a prototype shield?

Why can Shazam do this?

Can the Protection from Evil and Good spell be used on the caster?

Manuscript was "unsubmitted" because the manuscript was deposited in Arxiv Preprints

Why do UK politicians seemingly ignore opinion polls on Brexit?

Why don't Unix/Linux systems traverse through directories until they find the required version of a linked library?

Why is my p-value correlated to difference between means in two sample tests?

aging parents with no investments

What is the use of option -o in the useradd command?

What can other administrators access on my machine?



How to group records when rendering in HTML



The 2019 Stack Overflow Developer Survey Results Are InHow do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How to decide when to use Node.js?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I have a set of records which are fetch from a backend and returned grouped by Category using a javascript code.



Actually those records are simply render in HTML by string concatenation as below :



knowledge KB number 1 - Short description - Categor1
knowledge KB number 2 - Short description - Categor2
knowledge KB number 3 - Short description - Categor1
knowledge KB number 4 - Short description - Categor5
knowledge KB number 5 - Short description - Category6
knowledge KB number 6 - Short description - Category7
knowledge KB number 7 - Short description - Category5



What I am trying to represent is the set of record above render in HTML as below :



Category1 :
knowledge KB number 1 - Short description
knowledge KB number 3 - Short description



Category 2:
knowledge KB number 2 - Short description



Category 5:
knowledge KB number 4 - Short description
knowledge KB number 7 - Short description



Category 6:
knowledge KB number 5 - Short description



Category 7:
knowledge KB number 6 - Short description



How can I render my HTML in order that the Category is repeated only once per group



Here is below the sample code which represent them in concatained string :



GlideRecordSecure('u_kb_template_sharepoint_document');
kb.addQuery('cmdb_ci',current.sys_id);
kb.addQuery('latest',true);
kb.orderBy('kb_category');
kb.query();
"/>

<j2:if test="$[kb.next()]" >
<tr>
<td class="label label_spacing">
<span style="margin-right:3px; margin-left:1px;">$[SP]</span>
$gs.getMessage('Attached knowledge:')
</td>
<td>
<g2:evaluate>
var hasMore = true;
var category = kb.getDisplayValue('kb_category');
</g2:evaluate>
<j2:while test="$[hasMore]">
<div>
<img src="images/nav_bult.gifx" alt="$gs.getMessage('Knowledge Base Article')" />
<a class="obvious" target="_blank" href="$[kb.u_kb_url]">$[HTML:kb.number] - $[HTML:kb.short_description] - $[category]</a>
</div>
<g2:evaluate>
hasMore = kb.next();
</g2:evaluate>
</j2:while>
</td>
</tr>
</j2:if>


How can I update it to be grouped, did not find out ?



Note this script is part of Jelly element from ServiceNow



thanks










share|improve this question
























  • Please show us what you have tried and what your code looks like

    – Rust
    Mar 8 at 8:52











  • I have past my sample code snipet which show the concatenated part, but could not get the way for grouping

    – SCW
    Mar 8 at 10:11

















-1















I have a set of records which are fetch from a backend and returned grouped by Category using a javascript code.



Actually those records are simply render in HTML by string concatenation as below :



knowledge KB number 1 - Short description - Categor1
knowledge KB number 2 - Short description - Categor2
knowledge KB number 3 - Short description - Categor1
knowledge KB number 4 - Short description - Categor5
knowledge KB number 5 - Short description - Category6
knowledge KB number 6 - Short description - Category7
knowledge KB number 7 - Short description - Category5



What I am trying to represent is the set of record above render in HTML as below :



Category1 :
knowledge KB number 1 - Short description
knowledge KB number 3 - Short description



Category 2:
knowledge KB number 2 - Short description



Category 5:
knowledge KB number 4 - Short description
knowledge KB number 7 - Short description



Category 6:
knowledge KB number 5 - Short description



Category 7:
knowledge KB number 6 - Short description



How can I render my HTML in order that the Category is repeated only once per group



Here is below the sample code which represent them in concatained string :



GlideRecordSecure('u_kb_template_sharepoint_document');
kb.addQuery('cmdb_ci',current.sys_id);
kb.addQuery('latest',true);
kb.orderBy('kb_category');
kb.query();
"/>

<j2:if test="$[kb.next()]" >
<tr>
<td class="label label_spacing">
<span style="margin-right:3px; margin-left:1px;">$[SP]</span>
$gs.getMessage('Attached knowledge:')
</td>
<td>
<g2:evaluate>
var hasMore = true;
var category = kb.getDisplayValue('kb_category');
</g2:evaluate>
<j2:while test="$[hasMore]">
<div>
<img src="images/nav_bult.gifx" alt="$gs.getMessage('Knowledge Base Article')" />
<a class="obvious" target="_blank" href="$[kb.u_kb_url]">$[HTML:kb.number] - $[HTML:kb.short_description] - $[category]</a>
</div>
<g2:evaluate>
hasMore = kb.next();
</g2:evaluate>
</j2:while>
</td>
</tr>
</j2:if>


How can I update it to be grouped, did not find out ?



Note this script is part of Jelly element from ServiceNow



thanks










share|improve this question
























  • Please show us what you have tried and what your code looks like

    – Rust
    Mar 8 at 8:52











  • I have past my sample code snipet which show the concatenated part, but could not get the way for grouping

    – SCW
    Mar 8 at 10:11













-1












-1








-1








I have a set of records which are fetch from a backend and returned grouped by Category using a javascript code.



Actually those records are simply render in HTML by string concatenation as below :



knowledge KB number 1 - Short description - Categor1
knowledge KB number 2 - Short description - Categor2
knowledge KB number 3 - Short description - Categor1
knowledge KB number 4 - Short description - Categor5
knowledge KB number 5 - Short description - Category6
knowledge KB number 6 - Short description - Category7
knowledge KB number 7 - Short description - Category5



What I am trying to represent is the set of record above render in HTML as below :



Category1 :
knowledge KB number 1 - Short description
knowledge KB number 3 - Short description



Category 2:
knowledge KB number 2 - Short description



Category 5:
knowledge KB number 4 - Short description
knowledge KB number 7 - Short description



Category 6:
knowledge KB number 5 - Short description



Category 7:
knowledge KB number 6 - Short description



How can I render my HTML in order that the Category is repeated only once per group



Here is below the sample code which represent them in concatained string :



GlideRecordSecure('u_kb_template_sharepoint_document');
kb.addQuery('cmdb_ci',current.sys_id);
kb.addQuery('latest',true);
kb.orderBy('kb_category');
kb.query();
"/>

<j2:if test="$[kb.next()]" >
<tr>
<td class="label label_spacing">
<span style="margin-right:3px; margin-left:1px;">$[SP]</span>
$gs.getMessage('Attached knowledge:')
</td>
<td>
<g2:evaluate>
var hasMore = true;
var category = kb.getDisplayValue('kb_category');
</g2:evaluate>
<j2:while test="$[hasMore]">
<div>
<img src="images/nav_bult.gifx" alt="$gs.getMessage('Knowledge Base Article')" />
<a class="obvious" target="_blank" href="$[kb.u_kb_url]">$[HTML:kb.number] - $[HTML:kb.short_description] - $[category]</a>
</div>
<g2:evaluate>
hasMore = kb.next();
</g2:evaluate>
</j2:while>
</td>
</tr>
</j2:if>


How can I update it to be grouped, did not find out ?



Note this script is part of Jelly element from ServiceNow



thanks










share|improve this question
















I have a set of records which are fetch from a backend and returned grouped by Category using a javascript code.



Actually those records are simply render in HTML by string concatenation as below :



knowledge KB number 1 - Short description - Categor1
knowledge KB number 2 - Short description - Categor2
knowledge KB number 3 - Short description - Categor1
knowledge KB number 4 - Short description - Categor5
knowledge KB number 5 - Short description - Category6
knowledge KB number 6 - Short description - Category7
knowledge KB number 7 - Short description - Category5



What I am trying to represent is the set of record above render in HTML as below :



Category1 :
knowledge KB number 1 - Short description
knowledge KB number 3 - Short description



Category 2:
knowledge KB number 2 - Short description



Category 5:
knowledge KB number 4 - Short description
knowledge KB number 7 - Short description



Category 6:
knowledge KB number 5 - Short description



Category 7:
knowledge KB number 6 - Short description



How can I render my HTML in order that the Category is repeated only once per group



Here is below the sample code which represent them in concatained string :



GlideRecordSecure('u_kb_template_sharepoint_document');
kb.addQuery('cmdb_ci',current.sys_id);
kb.addQuery('latest',true);
kb.orderBy('kb_category');
kb.query();
"/>

<j2:if test="$[kb.next()]" >
<tr>
<td class="label label_spacing">
<span style="margin-right:3px; margin-left:1px;">$[SP]</span>
$gs.getMessage('Attached knowledge:')
</td>
<td>
<g2:evaluate>
var hasMore = true;
var category = kb.getDisplayValue('kb_category');
</g2:evaluate>
<j2:while test="$[hasMore]">
<div>
<img src="images/nav_bult.gifx" alt="$gs.getMessage('Knowledge Base Article')" />
<a class="obvious" target="_blank" href="$[kb.u_kb_url]">$[HTML:kb.number] - $[HTML:kb.short_description] - $[category]</a>
</div>
<g2:evaluate>
hasMore = kb.next();
</g2:evaluate>
</j2:while>
</td>
</tr>
</j2:if>


How can I update it to be grouped, did not find out ?



Note this script is part of Jelly element from ServiceNow



thanks







javascript html-table servicenow jelly






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 10:11







SCW

















asked Mar 8 at 8:50









SCWSCW

143




143












  • Please show us what you have tried and what your code looks like

    – Rust
    Mar 8 at 8:52











  • I have past my sample code snipet which show the concatenated part, but could not get the way for grouping

    – SCW
    Mar 8 at 10:11

















  • Please show us what you have tried and what your code looks like

    – Rust
    Mar 8 at 8:52











  • I have past my sample code snipet which show the concatenated part, but could not get the way for grouping

    – SCW
    Mar 8 at 10:11
















Please show us what you have tried and what your code looks like

– Rust
Mar 8 at 8:52





Please show us what you have tried and what your code looks like

– Rust
Mar 8 at 8:52













I have past my sample code snipet which show the concatenated part, but could not get the way for grouping

– SCW
Mar 8 at 10:11





I have past my sample code snipet which show the concatenated part, but could not get the way for grouping

– SCW
Mar 8 at 10:11












1 Answer
1






active

oldest

votes


















0














First of all, this isn't really an HTML issue, although you need to think of course how you want to visually represent this. I.e., the result will be a table with dynamic entries.



Now on the main question - 'How to show category only once' - you will need to do something like this in javascript (pseudo-code) - assume 'records' is an array containing those 7 records.



  • records.sort(by category) --> assuming the strings are not yet concatenated, and you can access category as single variable

  • records.foreach(item)
    compare previous item to current item
    if different create new HTML line, print category (otherwise stay in same line)
    if categories are same, just append the string
    previousitem = item

--> So you sort your data by 'category', thus they are grouped next to each in the data. Then can compare each record with the next one so you can put the right logic for generating the respective HTML.






share|improve this answer























  • this is what i am not familar with on how to build this dynamic html, do you have sample?

    – SCW
    Mar 8 at 10:13











  • So, I don't know Jelly and ServiceNow for this context, therefore this expands the scope of the original question. But basically, you need to infuse your logic at the right place of the HTML structure. I see you already have 'orderby(Category)' in your logic. Now you need to put things like (if previouscategory = currentcategory) in front of the <tr> tag. I.e., only have the '<tr>' tag when new category comes.

    – Erik Reder
    Mar 8 at 16:19











Your Answer






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: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f55059612%2fhow-to-group-records-when-rendering-in-html%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














First of all, this isn't really an HTML issue, although you need to think of course how you want to visually represent this. I.e., the result will be a table with dynamic entries.



Now on the main question - 'How to show category only once' - you will need to do something like this in javascript (pseudo-code) - assume 'records' is an array containing those 7 records.



  • records.sort(by category) --> assuming the strings are not yet concatenated, and you can access category as single variable

  • records.foreach(item)
    compare previous item to current item
    if different create new HTML line, print category (otherwise stay in same line)
    if categories are same, just append the string
    previousitem = item

--> So you sort your data by 'category', thus they are grouped next to each in the data. Then can compare each record with the next one so you can put the right logic for generating the respective HTML.






share|improve this answer























  • this is what i am not familar with on how to build this dynamic html, do you have sample?

    – SCW
    Mar 8 at 10:13











  • So, I don't know Jelly and ServiceNow for this context, therefore this expands the scope of the original question. But basically, you need to infuse your logic at the right place of the HTML structure. I see you already have 'orderby(Category)' in your logic. Now you need to put things like (if previouscategory = currentcategory) in front of the <tr> tag. I.e., only have the '<tr>' tag when new category comes.

    – Erik Reder
    Mar 8 at 16:19















0














First of all, this isn't really an HTML issue, although you need to think of course how you want to visually represent this. I.e., the result will be a table with dynamic entries.



Now on the main question - 'How to show category only once' - you will need to do something like this in javascript (pseudo-code) - assume 'records' is an array containing those 7 records.



  • records.sort(by category) --> assuming the strings are not yet concatenated, and you can access category as single variable

  • records.foreach(item)
    compare previous item to current item
    if different create new HTML line, print category (otherwise stay in same line)
    if categories are same, just append the string
    previousitem = item

--> So you sort your data by 'category', thus they are grouped next to each in the data. Then can compare each record with the next one so you can put the right logic for generating the respective HTML.






share|improve this answer























  • this is what i am not familar with on how to build this dynamic html, do you have sample?

    – SCW
    Mar 8 at 10:13











  • So, I don't know Jelly and ServiceNow for this context, therefore this expands the scope of the original question. But basically, you need to infuse your logic at the right place of the HTML structure. I see you already have 'orderby(Category)' in your logic. Now you need to put things like (if previouscategory = currentcategory) in front of the <tr> tag. I.e., only have the '<tr>' tag when new category comes.

    – Erik Reder
    Mar 8 at 16:19













0












0








0







First of all, this isn't really an HTML issue, although you need to think of course how you want to visually represent this. I.e., the result will be a table with dynamic entries.



Now on the main question - 'How to show category only once' - you will need to do something like this in javascript (pseudo-code) - assume 'records' is an array containing those 7 records.



  • records.sort(by category) --> assuming the strings are not yet concatenated, and you can access category as single variable

  • records.foreach(item)
    compare previous item to current item
    if different create new HTML line, print category (otherwise stay in same line)
    if categories are same, just append the string
    previousitem = item

--> So you sort your data by 'category', thus they are grouped next to each in the data. Then can compare each record with the next one so you can put the right logic for generating the respective HTML.






share|improve this answer













First of all, this isn't really an HTML issue, although you need to think of course how you want to visually represent this. I.e., the result will be a table with dynamic entries.



Now on the main question - 'How to show category only once' - you will need to do something like this in javascript (pseudo-code) - assume 'records' is an array containing those 7 records.



  • records.sort(by category) --> assuming the strings are not yet concatenated, and you can access category as single variable

  • records.foreach(item)
    compare previous item to current item
    if different create new HTML line, print category (otherwise stay in same line)
    if categories are same, just append the string
    previousitem = item

--> So you sort your data by 'category', thus they are grouped next to each in the data. Then can compare each record with the next one so you can put the right logic for generating the respective HTML.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 9:10









Erik RederErik Reder

185110




185110












  • this is what i am not familar with on how to build this dynamic html, do you have sample?

    – SCW
    Mar 8 at 10:13











  • So, I don't know Jelly and ServiceNow for this context, therefore this expands the scope of the original question. But basically, you need to infuse your logic at the right place of the HTML structure. I see you already have 'orderby(Category)' in your logic. Now you need to put things like (if previouscategory = currentcategory) in front of the <tr> tag. I.e., only have the '<tr>' tag when new category comes.

    – Erik Reder
    Mar 8 at 16:19

















  • this is what i am not familar with on how to build this dynamic html, do you have sample?

    – SCW
    Mar 8 at 10:13











  • So, I don't know Jelly and ServiceNow for this context, therefore this expands the scope of the original question. But basically, you need to infuse your logic at the right place of the HTML structure. I see you already have 'orderby(Category)' in your logic. Now you need to put things like (if previouscategory = currentcategory) in front of the <tr> tag. I.e., only have the '<tr>' tag when new category comes.

    – Erik Reder
    Mar 8 at 16:19
















this is what i am not familar with on how to build this dynamic html, do you have sample?

– SCW
Mar 8 at 10:13





this is what i am not familar with on how to build this dynamic html, do you have sample?

– SCW
Mar 8 at 10:13













So, I don't know Jelly and ServiceNow for this context, therefore this expands the scope of the original question. But basically, you need to infuse your logic at the right place of the HTML structure. I see you already have 'orderby(Category)' in your logic. Now you need to put things like (if previouscategory = currentcategory) in front of the <tr> tag. I.e., only have the '<tr>' tag when new category comes.

– Erik Reder
Mar 8 at 16:19





So, I don't know Jelly and ServiceNow for this context, therefore this expands the scope of the original question. But basically, you need to infuse your logic at the right place of the HTML structure. I see you already have 'orderby(Category)' in your logic. Now you need to put things like (if previouscategory = currentcategory) in front of the <tr> tag. I.e., only have the '<tr>' tag when new category comes.

– Erik Reder
Mar 8 at 16:19



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • 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.

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%2fstackoverflow.com%2fquestions%2f55059612%2fhow-to-group-records-when-rendering-in-html%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

1928 у кіно

Захаров Федір Захарович

Ель Греко