My Kendo Grid accepts the following json format
{"GetAllStratagyResult":[{"Id":14,"Region":"xxx","Terminal":"NGAY-HG6","Type":1,"VerisonNumber":"5476","VersionDate":"\/Date(1427782421023+0400)\/","VersionName":"Second Version1","content":"<p><span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit<\/span><\/p><p><span>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.<\/span><\/p><p><span>Proin pharetra novnummy pede.<\/span><\/p><p>cccccccccc<\/p>"},{"Id":15,"Region":"yyy","Terminal":"NGAY-HG6","Type":1,"VerisonNumber":"456","VersionDate":"\/Date(1427722608457+0400)\/","VersionName":"Second Version1","content":"Lorem ipsum dolor sit amet, consectetuer adipiscing elit."},{"Id":16,"Region":"zzz","Terminal":"NGAY-HG6","Type":1,"VerisonNumber":"456","VersionDate":"\/Date(1427722395997+0400)\/","VersionName":"Second Version1","content":"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."}]
but it won't show column value for following json:
{"readexcelbyteResult":"[{\"IFRS\":\"Volume\",\"2001\":\"645645\",\"2002\":\"875\",\"2003\":\"8598\",\"2004\":\"6986\",\"2005\":\"98698\",\"2006\":\"698698\",\"2007\":\"6989698\",\"2008\":\"57487\",\"2009\":\"487487\",\"2010\":\"4875\",\"2011\":\"458\"},{\"IFRS\":\"ipsum \",\"2001\":\"456456\",\"2002\":\"6986\",\"2003\":\"98698\",\"2004\":\"6986\",\"2005\":\"986\",\"2006\":\"98698\",\"2007\":\"698698\",\"2008\":\"6986\",\"2009\":\"98698\",\"2010\":\"69860606\",\"2011\":\"9860\"},{\"IFRS\":\"dolor \",\"2001\":\"366397\",\"2002\":\"4364\",\"2003\":\"98308\",\"2004\":\"467\",\"2005\":\"4086\",\"2006\":\"40874\",\"2007\":\"6487\",\"2008\":\"4984\",\"2009\":\"8749\",\"2010\":\"87598\",\"2011\":\"4874\"},{\"IFRS\":\"amet\",\"2001\":\"646456\",\"2002\":\"875\",\"2003\":\"8598\",\"2004\":\"6986\",\"2005\":\"98698\",\"2006\":\"698698\",\"2007\":\"6989698\",\"2008\":\"57487\",\"2009\":\"487487\",\"2010\":\"4875\",\"2011\":\"458\"},{\"IFRS\":\"consectetuer \",\"2001\":\"645645\",\"2002\":\"6986\",\"2003\":\"98698\",\"2004\":\"6986\",\"2005\":\"986\",\"2006\":\"98698\",\"2007\":\"698698\",\"2008\":\"6986\",\"2009\":\"98698\",\"2010\":\"69860606\",\"2011\":\"9860\"},{\"IFRS\":\"adipiscing \",\"2001\":\"536397\",\"2002\":\"4364\",\"2003\":\"98308\",\"2004\":\"467\",\"2005\":\"4086\",\"2006\":\"40874\",\"2007\":\"6487\",\"2008\":\"4984\",\"2009\":\"8749\",\"2010\":\"87598\",\"2011\":\"4874\"},{\"IFRS\":\"Maecenas \",\"2001\":\"456456\",\"2002\":\"875\",\"2003\":\"8598\",\"2004\":\"6986\",\"2005\":\"98698\",\"2006\":\"698698\",\"2007\":\"6989698\",\"2008\":\"57487\",\"2009\":\"487487\",\"2010\":\"4875\",\"2011\":\"458\"},{\"IFRS\":\"porttitor \",\"2001\":\"564564\",\"2002\":\"6986\",\"2003\":\"98698\",\"2004\":\"6986\",\"2005\":\"986\",\"2006\":\"98698\",\"2007\":\"698698\",\"2008\":\"6986\",\"2009\":\"98698\",\"2010\":\"69860606\",\"2011\":\"9860\"},{\"IFRS\":\"congue \",\"2001\":\"366397\",\"2002\":\"4364\",\"2003\":\"98308\",\"2004\":\"467\",\"2005\":\"4086\",\"2006\":\"40874\",\"2007\":\"6487\",\"2008\":\"4984\",\"2009\":\"8749\",\"2010\":\"87598\",\"2011\":\"4874\"}]"}
All my schemas, model and structure of json response are the same.
Please someone help me
In the second case you have quotes before the array of element { "readexcelbyteResult":"[ , that makes the system understand it as string and not as an array of data. Also, all the elements seems to have an extra escape character before the quotes \"IFRS\":\"Volume\" should be: "IFRS":"Volume"
So, it should looks like:
{"readexcelbyteResult":[{"IFRS":"Volume","2001":"645645","2002":"875","2003":"8598","2004":"6986","2005":"98698","2006":"698698","2007":"6989698","2008":"57487","2009":"487487","2010":"4875","2011":"458"},{"IFRS":"ipsum","2001":"456456","2002":"6986","2003":"98698","2004":"6986","2005":"986","2006":"98698","2007":"698698","2008":"6986","2009":"98698","2010":"69860606","2011":"9860"},{"IFRS":"dolor ","2001":"366397","2002":"4364","2003":"98308","2004":"467","2005":"4086","2006":"40874","2007":"6487","2008":"4984","2009":"8749","2010":"87598","2011":"4874"}, {"IFRS":"amet","2001":"646456","2002":"875","2003":"8598","2004":"6986","2005":"98698","2006":"698698","2007":"6989698","2008":"57487","2009":"487487","2010":"4875","2011":"458"},{"IFRS":"consectetuer ","2001":"645645","2002":"6986","2003":"98698","2004":"6986","2005":"986","2006":"98698","2007":"698698","2008":"6986","2009":"98698","2010":"69860606","2011":"9860"},{"IFRS":"adipiscing ","2001":"536397","2002":"4364","2003":"98308","2004":"467","2005":"4086","2006":"40874","2007":"6487","2008":"4984","2009":"8749","2010":"87598","2011":"4874"},{"IFRS":"Maecenas ","2001":"456456","2002":"875","2003":"8598","2004":"6986","2005":"98698","2006":"698698","2007":"6989698","2008":"57487","2009":"487487","2010":"4875","2011":"458"},{"IFRS":"porttitor ","2001":"564564","2002":"6986","2003":"98698","2004":"6986","2005":"986","2006":"98698","2007":"698698","2008":"6986","2009":"98698","2010":"69860606","2011":"9860"},{"IFRS":"congue ","2001":"366397","2002":"4364","2003":"98308","2004":"467","2005":"4086","2006":"40874","2007":"6487","2008":"4984","2009":"8749","2010":"87598","2011":"4874"}]}
Related
I have an essay with sidenotes. The page has two columns, one for the essay, another for the sidenotes. If a sentence has a sidenote, it is followed by a number in parentheses. The number is the sidenote number. For example: Essay: The sun circles the earth. (1) Sidenote: (1) Wrong!
My goal is to make all the numbers+parentheses smaller. I assume there is a simple CSS solution.
I should add that there are 80 different notes, hence my need for a simple, time-saving solution. Is there one that would allow me to say, "for every (n) where n is a number, make font 8pt"?
If you're looking for a pure CSS solution, you're out of luck. CSS is unable to parse text and manipulate the DOM—that is the work of JavaScript. If you are able to manually change the markup, you can wrap your citations, e.g. (1), with a semantic element, such as <sup>(1)</sup> if you want it to appear as superscript, or <span>(1)</span> if you want to style it otherwise. Given that you wanted Wikipedia-style citations, the former would be the way to go.
However, if you want the browser to parse your digits in parenthesis on-the-go, CSS alone is insufficient—you will have to use JS. As mentioned before, the best way to find such citations is to look for a format, for example, the following regex pattern will probably suffice: \(\d+\). However, it again depends on how you want them to be match. If you do not want them to match erroneously to normal bracketed numbers, such as within sentences, or in bulleted points, you will have to include a negated whitespace character before it: [^\s]\(\d+\).
Here is a simple example with JS+CSS combined:
$(function() {
$('p').each(function() {
$(this).html($(this).html().replace(/[^\s](\(\d+\))/gi,'<sup>$1</sup>'));
});
});
sup {
color: blue;
font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus interdum ullamcorper, for example: (1) Suspendisse semper mattis ante, et efficitur justo tempor in; (2) Cras iaculis, magna a bibendum porta, diam massa ornare nisi, eget finibus sapien enim non elit; (3) Pellentesque ut ultrices libero.</p>
<p>Donec non velit et ante vestibulum maximus(1). Phasellus ac interdum nisi, eu iaculis massa. Proin vel sem est. Morbi euismod massa eu commodo efficitur. Phasellus vitae leo euismod, pretium turpis sit amet, bibendum elit(2). In efficitur id metus ullamcorper tristique. Integer et felis in felis suscipit tincidunt nec nec lectus.</p>
<p>Vestibulum mollis, magna sodales maximus faucibus, leo risus pretium libero, at placerat urna eros et nisl(3). Nunc cursus enim diam, in accumsan augue faucibus vel. Integer feugiat egestas lectus eu blandit. Donec ac neque turpis. Donec imperdiet feugiat purus, a congue dui convallis ut(4). Sed scelerisque ac massa non feugiat. Aliquam erat volutpat. Donec vestibulum odio id pulvinar elementum. Ut laoreet massa ac nibh pulvinar, id consequat tellus malesuada(5). Fusce porta purus diam, in luctus odio laoreet quis. Quisque condimentum condimentum felis sed rutrum. Aenean pellentesque felis in posuere efficitur. Mauris tristique ultricies massa at euismod.</p>
If you want a CSS solution, you could use the following:
HTML
<b>Essay:</b> The sun circles the earth. <span class="sidenote-number">(1)</span>
<b>Sidenote:</b> <span class="sidenote-number">(1)</span> Wrong!
CSS
.sidenote-number {
font-size: 10px;
}
The style in the sidenote-number class will be applied to the text inside of the spans.
Demo
What you may be looking for is the HTML <sup> (or <sub>) notation.
They stand for subscript and superscript respectively. The sub tag will allow you to create 'Wikipedia like' small numbers.
Example of superscript [1] (<sup>[1]</sup>)
Example of subscript [1] (<sub>[1]</sub>)
Here is a solution based on my comment. It amounts to a trivialized reference management system like bibtex.
Comment:
Maybe what you really want, is to use
every place you want a numbered side note, and then use javascript to
go through and automatically number and format them. That would be a
tradeoff between having to declare the span classes but not having to
keep track of your sidenote numbers.
This way, instead of hard-coding the side note numbers, you could add, remove or rearrange the notations, and they would still be automatically numbered properly.
http://jsfiddle.net/abalter/z43gxsfy/
html:
<h1>Cascading Style Sheets (CSS)</h1>
<p>Cascading Style Sheets (CSS) is a style sheet language used for describing the
look and formatting of a document written in a markup
language <span class="sidenote" data-source="src1"></span>.
Although most often used to change the style of web pages and user
interfaces written in HTML and XHTML, the language can be applied to
any kind of XML document, including plain XML, SVG and XUL. Along with
HTML and JavaScript, CSS is a cornerstone technology used by most websites
to create visually engaging webpages, user interfaces for web applications,
and user interfaces for many mobile applications <span class="sidenote" data-source="src2"></span>.</p>
<h3>References</h3>
<ul id='references'></ul>
CSS:
#references {
list-style: none;
}
.sidenote {
font-size: 0.8em;
}
Javascript:
var sources = {
src1: "Article by so and so in such and such",
src2: "Book by someone"
};
var sidenotes = $('.sidenote');
$('.sidenote').each(function(index){
$(this).html('(' + (index+1) + ')');
$('#references').append($('<li>').html("(" + (index+1) + ") " + sources[$(this).data('source')]));
});
Untested regex/javascript/jquery solution:
$(document).ready(function()
{
walk(document.body);
});
//Iterate through every part of the page
function walk(node)
{
// I stole this function from here:
// http://is.gd/mwZp7E
var child, next;
switch (node.nodeType)
{
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild;
while(child)
{
next = child.nextSibling;
walk(child);
child = next;
}
break;
case 3: // Text node
check(node);
break;
}
//Check if the text node contains parentheses.
function check(node)
{
var v = textNode.nodeValue;
var res = v.match(/\(*.\)/g); //Match anything inside of parentheses
if(res)
{
v.style.fontSize = "8px"; //Not sure if that part would actually work
}
textNode.nodeValue = v;
}
Am trying to do a replacement of customized tags with html tags in my website as follows:
[block-2] "Donec volutpat nibh sit amet libero ornare non laoreet arcu luctus. Donec id arcu quis mauris". [/block-2]
If the above [block] tag is encountered, it should be replaced by some html tags (using regexp), specifically:
<blockquote class="tm-style2"><span>
"Donec volutpat nibh sit amet libero ornare non laoreet arcu luctus. Donec id arcu quis mauris".
</span></blockquote>
I have tried the following but is not working. Please help:
$article_text = preg_replace_callback(
"(\[block-([0-9]+)\](.+)\[\/block-([0-9]+)\])",
create_function('$p','return "<blockquote class=\"tm-style".$p[1]."\"><span>".$p[2]."</span></blockquote>";'), $article_text);
You don't actually need to use preg_replace_callback function, just preg_replace would be fine.
\[(block-([0-9]+))\](.+?)\[\/\1\]
Then replace the matched characters with
<blockquote class="tm-style\2"><span>\n\3\n</span></blockquote>
DEMO
$re = "~\\[(block-([0-9]+))\\](.+?)\\[\\/\\1\\]~m";
$str = "[block-2] \"Donec volutpat nibh sit amet libero ornare non laoreet arcu luctus. Donec id arcu quis mauris\". [/block-2]";
$subst = '<blockquote class="tm-style\2"><span>'."\n".'\3'."\n".'</span></blockquote>';
$result = preg_replace($re, $subst, $str);
echo $result;
Output:
<blockquote class="tm-style2"><span>
"Donec volutpat nibh sit amet libero ornare non laoreet arcu luctus. Donec id arcu quis mauris".
</span></blockquote>
You need to escape closing tag's backslash in your pattern ...[\/block....
So full pattern is (\[block-([0-9]+)\](.+)\[\/block-([0-9]+)\])
What I am trying to do is find a chunk of HTML that has comments chunk!--/block--> and move it in its entirety right after header. The thing is that the comment always remains the same but the chunk varies through pages using find and replace in Dreamweaver. Here is a quick sample:
<!--header-->
<header>Hello</header>
<!--/header-->
This is where the chunk needs to be moved
<h1>Hello content</h1>
<p>lorem ipsum</p>
This is the chunk, it has a starting comment and ending one, I thought it might be used as a references for RegEx including everything inside.
<!--block-->
<p>hello world</p>
<!--/block-->
Ok. You didn't specify the language for reular expression but this PHP code does what you need I just wrote it and tested it. As a bonus I wrote the final result back to the source page.
First you have your original file, I called mine source.php
<!--header--> <header>SO HERE IS THE HEADER</header> <!--/header-->
<div>this is information that is above ID CARR, but will be below the div ID carr once php is done executing..</div>
<div id="carr"> Phasellus laoreet dolor magna, et tempor mi dictum eu. Aenean pellentesque vulputate tortor. Vestibulum odio velit, faucibus sed dui non, laoreet facilisis sem. Curabitur a magna ligula. Cras cursus vel dui placerat posuere. Donec ullamcorper risus eu lobortis dignissim. Nullam fermentum est diam, sed lacinia sapien ornare et. </div> <div>here is more informatin on the bottom</div>
Then you have another page called index.php that does what you want. In this example I am targeting the above.
<?php
$page_path = 'source.php';
$source = file_get_contents($page_path);
$regex = '#\<div id="carr">(.+?)\</div>#s';
preg_match($regex, $source, $matches);
$match = $matches[0];
$a = explode("</header>", $source);
//strip out what we found with regular expression
$first = str_replace($match, '', $source);
//append it to the place where you need it.
$final = str_replace('<!--/header-->', '<!--/header-->'.$match, $first);
echo $final;
$fp = fopen($page_path, 'w+');//w+ erases r+ point at begining of file.
fwrite($fp, $final);
fclose($fp);
?>
this is the scenario
I have a Word document ( .docx ) which i want to convert in a template, saving it as a "XML Word 2003" file. Inside the document content, i put a custom tag named {MY_CONTENT} which will be replaced with HTML code.
When I generate a word document like this, it didn't open properly. This is the HTML code i'm trying to insert into the Word Xml document:
<div style='text-align: center;'>
<b><font size='3'>Contract</font></b>
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin quis justo elementum,
vehicula ante vel, facilisis ante. Aenean dolor lectus, cursus in mattis sed, ullamcorper ut quam.
Quisque fringilla erat sit amet blandit euismod. Integer nec odio vel erat molestie fringilla.
Aliquam tempor ac urna vitae convallis. Praesent mattis massa eget lectus mattis,
non imperdiet ipsum suscipit. Phasellus gravida eros turpis, et faucibus libero gravida
non.
Aliquam ultricies nisl eget magna tincidunt tincidunt. Proin feugiat interdum nibh nec rutrum.
In hac habitasse platea dictumst. Etiam ac condimentum nisl, et volutpat mauris.
Mauris erat dui, aliquam ut urna vel, euismod placerat est.
<font size='3'></font>
</div>
I tried to "htmlencode" the html code above, but still the document is not opened property.
If it was possible to "traslate" a HTML piece of code into Word xml tags, i think it could be resolved.
... or is there a way to display the html code into the word xml document, without converting it or applying sorcery ?
Thanx in advance.
Thanx for your kind comments. I stored them in my PKDB ( personal knowledge database ) :) for further uses.
Finally, I decided to use ITEXTSHARP library to generate the document, because it gives me the tools to insert HTML code without formatting isues.
I inserted an image template as background, wrote the HTML code, and that's all.
Hope this piece of code to be useful for any person
This is the code
string pathImagenPlantilla = Server.MapPath(<path_of_the_image_template>);
//generar el pdf al vuelo
string filenamePDF = "Your_Document_Name.pdf";
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filenamePDF);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
//load the image template
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(pathImagenPlantilla);
//define your HTML code
StringBuilder strTextoHTML = new StringBuilder();
strTextoHTML.Append("<html>");
strTextoHTML.Append("<body>");
strTextoHTML.Append(<your HTML CODE right here>);
strTextoHTML.Append("</body>");
strTextoHTML.Append("</html>");
// margins, in milimeters
float margenIzquierdo = 25;
float margenDerecho = 25 ;
float margenSuperior = 25 ;
float margenInferior = 10 ;
Document pdfDoc = new Document(PageSize.A4, margenIzquierdo, margenDerecho, margenSuperior, margenInferior);
//Adjust the size of image template , to the screen size
float pageWidth = pdfDoc.PageSize.Width - (margenIzquierdo + margenDerecho);
float pageHeight = pdfDoc.PageSize.Height - (margenInferior + margenSuperior);
jpg.SetAbsolutePosition(margenIzquierdo, margenInferior);
jpg.ScaleToFit(pageWidth, pageHeight);
//If you want to choose image as background then,
jpg.Alignment = iTextSharp.text.Image.UNDERLYING;
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.NewPage();
//add image template
pdfDoc.Add(jpg);
//add html code
foreach (IElement E in HTMLWorker.ParseToList(new StringReader(strTextoHTML.ToString()), new StyleSheet()))
{
pdfDoc.Add(E);
}
//close doc and display/download
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
Regards,
Should have been very easy but somehow cannot get it to work. I want to display truncated text on my blog home page with a 'read more' link that shows up inline with the text i.e.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ac tortor et felis aliquet vestibulum sed in sem. Aliquam pharetra ultricies nunc, non pellentesque ... Read More
Since I use simple_format for my text, all breaks in the text get wrapped in tags and I get Read More in a separate line as below
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ac tortor et felis aliquet vestibulum sed in sem. Aliquam pharetra ultricies nunc, non pellentesque ...
Read More
How do I place it inline after a < p > tag. Guess it's more of a CSS question rather than a Rails one. Again, I feel this should be super simple. What am I forgetting?
Here's the code snippet in the view
<%= simple_format truncate(h(feed.description), length: 400, separator: ' ') %><%= link_to "Read More", feed_path(feed)%>
I suspect that you can just put your link inside the simple_format content-parameter link this:
<%= simple_format truncate((h(feed.description) + link_to("Read More", feed_path(feed))), length: 400, separator: ' ') %>
(Note: not tested)