Permalink
Browse files

first draft of slick grid export added

  • Loading branch information...
1 parent b215d06 commit 4feb08d3c9b582718d7982ab0f7ba9c7a805dc10 @erikriverson committed Sep 18, 2012
Showing with 107 additions and 5 deletions.
  1. +2 −0 DESCRIPTION
  2. +11 −5 R/html.R
  3. +94 −0 R/slickgrid.R
View
@@ -9,6 +9,7 @@ Suggests:
ggplot2
Imports:
grDevices,
+ RJSONIO,
Hmisc
Description: The mutable package allows users to construct objects
representing arbitrary tabular material and output the object into a
@@ -27,6 +28,7 @@ Collate:
'hlf.R'
'html.R'
'mathjax.R'
+ 'slickgrid.R'
'latex.R'
'plain.R'
'response.R'
View
@@ -1,6 +1,7 @@
#' @S3method html mutable
html.mutable <- function(object, na.print = "<td></td>", file = "",
headerFunction = muHTMLTableHeader,
+ markupFunction = muHTMLMarkupGenerator,
footerFunction = muHTMLTableFooter,
documentHeaderFunction = muHTMLDocHeader,
documentFooterFunction = muHTMLDocFooter,
@@ -27,11 +28,8 @@ html.mutable <- function(object, na.print = "<td></td>", file = "",
cat(paste(headerFunction(x, caption, footnote, ...),
collapse = newline), newline,
file = file, append = completeDocument)
-
- cat(paste("", apply(x, 1, paste, collapse = " "),
- collapse = ps("</tr>", newline)),
- ps("</tr>", newline), file = file,
- append = TRUE)
+
+ markupFunction(x, file)
cat(paste(footerFunction(x), collapse = newline), newline,
file = file, append = TRUE)
@@ -45,6 +43,14 @@ html.mutable <- function(object, na.print = "<td></td>", file = "",
invisible(ret)
}
+muHTMLMarkupGenerator <- function(x, file) {
+ cat(paste("", apply(x, 1, paste, collapse = " "),
+ collapse = ps("</tr>", newline)),
+ ps("</tr>", newline), file = file,
+ append = TRUE)
+
+}
+
#' @export
print.mutableHTML <- function(x, completeDocument = TRUE, browser) {
View
@@ -0,0 +1,94 @@
+library(Hmisc)
+library(RJSONIO)
+
+df1 <- data.frame(a = 1:10, b = 2:11, c = gl(2,10))
+summary(df1)
+
+##
+################################################################################
+
+################################################################################
+## markup generation
+
+html(mutable(df1))
+m1 <- mutable(c ~ a + b, data = df1)
+
+m2 <- mutable(mtcars)
+
+html(m2,
+ documentHeaderFunction = muSlickGridDocHeader,
+ headerFunction = muSlickGridHeader,
+ markupFunction = muSlickGridMarkupGenerator,
+ footerFunction = muSlickGridFooter,
+ documentFooterFunction = muSlickGridDocFooter,
+ completeDocument = TRUE,
+ markupElement = "plain",
+ file = "/work/eiverson/projects/src/SlickGrid/examples/mut1.html")
+
+##
+################################################################################
+
+muSlickGridMarkupGenerator <- function(x, file) {
+ cat(c('var data = ',
+ toJSON(x) , ";\n"), file = file, append = TRUE)
+}
+
+muSlickGridHeader <- function(x, caption, footnote) {
+ c('<script>',
+ 'var grid;',
+ 'var columns = [',
+ paste('{id: "',
+ colnames(x),
+ '", name: "',
+ colnames(x),
+ '", field: "',
+ colnames(x),
+ '"},', sep = ""),
+ ' ];',
+ '',
+ 'var options = {',
+ ' enableCellNavigation: true,',
+ ' enableColumnReorder: false',
+ '};',
+ '')
+}
+
+muSlickGridFooter <- function(x) {
+ c('$(function () {',
+ 'grid = new Slick.Grid("#myGrid", data, columns, options);',
+ '})',
+ '</script>')
+}
+
+muSlickGridDocFooter <- muHTMLDocFooter
+
+muSlickGridDocHeader <- function(cssFile) {
+ c('<!DOCTYPE HTML>',
+ '<html>',
+ '<head>',
+ '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">',
+ '<title>SlickGrid example 1: Basic grid 2</title>',
+ '<link rel="stylesheet" href="../slick.grid.css" type="text/css"/>',
+ '<link rel="stylesheet" href="../css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css"/>',
+ '<link rel="stylesheet" href="examples.css" type="text/css"/>',
+ '</head>',
+ '<body>',
+ '<table width="100%">',
+ '<tr>',
+ '<td valign="top" width="50%">',
+ '<div id="myGrid" style="width:700px;height:500px;"></div>',
+ '</td>',
+ '<td valign="top">',
+ '<h2>Demonstrates:</h2>',
+ '<ul>',
+ '<li>basic grid with minimal configuration</li>',
+ '</ul>',
+ '</td>',
+ '</tr>',
+ '</table>',
+ '<script src="../lib/jquery-1.7.min.js"></script>',
+ '<script src="../lib/jquery.event.drag-2.0.min.js"></script>',
+ '<script src="../slick.core.js"></script>',
+ '<script src="../slick.grid.js"></script>')
+}
+

0 comments on commit 4feb08d

Please sign in to comment.